Java Collections class

Java collection class is used exclusively with static methods that operate on or return collections. It inherits Object class.

Collections class declaration

public class Collections extends Object

Methods of Java Collections class

static boolean addAll(Collection c, T... elements) It is used to add all of the specified elements to the specified collection.

It is used to add all of the specified elements to the specified collection. It is used to return a view of a Deque as a Last-In-First-Out (LIFO) Queue.

static int binarySearch(List list, T key, Comparator It is used to search the specified list for the specified object using the binary search algorithm.

static List checkedList(List list, Class type) It is used to return a dynamically typesafe view of the specified list.

static Set checkedSet(Set s, Class type) It is used to return a dynamically typesafe view of the specified set.

static T max(Collection coll, Comparator comp) It is used to return the maximum element of the given collection, according to the order induced by the specified comparator.

static T extends Object & Comparable>T min(Collection coll) It is used to return the minimum element of the given collection, according to the natural ordering of its elements.

static boolean replaceAll(List list, T oldVal, T newVal) It is used to replace all occurrences of one specified value in a list with another.

EXAMPLE

Flash Soon