Java Collections Class Methods

The Java Collections framework provides a set of static utility methods that operate on or return collections. These methods are part of the java.util.Collections class, which is designed to simplify and streamline common tasks associated with handling collections. Whether you’re working with lists, sets, or maps, the Collections class offers methods for tasks such as sorting, searching, and thread-safe operations.

Java Collections Class Methods

The table below contains various methods of the Java java.util.Collections class, each with a link to a detailed explanation, examples, and real-world uses. Click on the method names to learn more about how to use them effectively in your applications.

Method Description
addAll() Adds all of the specified elements to the specified collection.
asLifoQueue() Returns a view of a Deque as a Last-in-first-out (Lifo) Queue.
binarySearch() Searches the specified list for the specified object using the binary search algorithm.
checkedList() Returns a dynamically typesafe view of the specified list.
checkedCollection() Returns a dynamically typesafe view of the specified collection.
checkedMap() Returns a dynamically typesafe view of the specified map.
copy() Copies all of the elements from one list into another.
disjoint() Returns true if the two specified collections have no elements in common.
emptyEnumeration() Returns an empty enumeration.
emptyIterator() Returns an empty iterator.
emptyList() Returns the empty list (immutable).
emptyListIterator() Returns an empty list iterator.
emptyMap() Returns the empty map (immutable).
emptyNavigableMap() Returns an empty navigable map (immutable).
emptyNavigableSet() Returns an empty navigable set (immutable).
emptySortedMap() Returns an empty sorted map (immutable).
emptySortedSet() Returns an empty sorted set (immutable).
fill() Replaces all of the elements of the specified list with the specified element.
frequency() Returns the number of elements in the specified collection equal to the specified object.
indexOfSubList() Returns the starting position of the first occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.
list() Returns an array list containing the enumeration’s elements.
max() Returns the maximum element of the given collection, according to the natural ordering of its elements.
min() Returns the minimum element of the given collection, according to the natural ordering of its elements.
nCopies() Returns an immutable list consisting of n copies of the specified object.
newSequencedSetFromMap() Returns a SequencedSet backed by the specified map.
newSetFromMap() Returns a set backed by the specified map.
replaceAll() Replaces all occurrences of one specified value in a list with another.
reverse() Reverses the order of the elements in the specified list.
reverseOrder() Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.
shuffle() Randomly permutes the elements in the specified list.
singleton() Returns an immutable set containing only the specified object.
singletonList() Returns an immutable list containing only the specified object.
singletonMap() Returns an immutable map containing only the specified key-value pair.
swap() Swaps the elements at the specified positions in the specified list.
synchronizedCollection() Returns a synchronized (thread-safe) collection backed by the specified collection.
synchronizedList() Returns a synchronized (thread-safe) list backed by the specified list.
synchronizedMap() Returns a synchronized (thread-safe) map backed by the specified map.
synchronizedNavigableSet() Returns a synchronized (thread-safe) navigable set backed by the specified navigable set.
synchronizedSet() Returns a synchronized (thread-safe) set backed by the specified set.
synchronizedSortedMap() Returns a synchronized (thread-safe) sorted map backed by the specified sorted map.
synchronizedSortedSet() Returns a synchronized (thread-safe) sorted set backed by the specified sorted set.
unmodifiableCollection() Returns an unmodifiable view of the specified collection.
unmodifiableList() Returns an unmodifiable view of the specified list.
unmodifiableMap() Returns an unmodifiable view of the specified map.
unmodifiableNavigableMap() Returns an unmodifiable view of the specified navigable map.
unmodifiableNavigableSet() Returns an unmodifiable view of the specified navigable set.
unmodifiableSequencedCollection() Returns an unmodifiable view of the specified sequenced collection.
unmodifiableSequencedMap() Returns an unmodifiable view of the specified sequenced map.
unmodifiableSequencedSet() Returns an unmodifiable view of the specified sequenced set.
unmodifiableSet() Returns an unmodifiable view of the specified set.

For more details, visit the Java API Documentation – Collections API.

Leave a Comment

Scroll to Top