Java Collections tutorial with example program


Class Collections

public class Collections
extends Object
{
   //
}
  
Since:
1.2
See Also:
Collection, Set, List, Map

Method Summary
static boolean addAll(Collection c, T... elements)
Adds all of the specified elements to the specified collection.
static Queue asLifoQueue(Deque deques)
Returns a view of a Deque as a Last-in-first-out (Lifo) Queue.
static int binarySearch(List> list, T key)
Searches the specified list for the specified object using the binary search algorithm.
static int binarySearch(List list, T key, Comparator c)
Searches the specified list for the specified object using the binary search algorithm.
static Collection checkedCollection(Collection c ,Class type)
Returns a dynamically typesafe view of the specified collection.
static List  checkedList(List list, Class type)
Returns a dynamically typesafe view of the specified list.
static Map checkedMap(Map m, Class keyType, Class valueType)
Returns a dynamically typesafe view of the specified map.
static Set checkedSet(Set s, Class type)
Returns a dynamically typesafe view of the specified set.

static SortedMap checkedSortedMap(SortedMap m, Class keyType, Class valueType)
Returns a dynamically typesafe view of the specified sorted map.
static SortedSet checkedSortedSet(SortedSet s, Class type)
Returns a dynamically typesafe view of the specified sorted set.
static void copy(List dest, List src)
Copies all of the elements from one list into another.
static boolean disjoint(Collection c1, Collection c2)
Returns true if the two specified collections have no elements in common.
static Enumeration emptyEnumeration()
Returns an enumeration that has no elements.
static Iterator emptyIterator()
Returns an iterator that has no elements.
static List emptyList()
Returns the empty list (immutable).
static ListIterator  emptyListIterator()
Returns a list iterator that has no elements.
static Map emptyMap()
Returns the empty map (immutable).
static Set emptySet()
Returns the empty set (immutable).
static Enumeration enumeration(Collection c)
Returns an enumeration over the specified collection.
static void fill(List list, T obj)
Replaces all of the elements of the specified list with the specified element.
static int frequency(Collection c, Object o)
Returns the number of elements in the specified collection equal to the specified object.
static int indexOfSubList(List source, List target)
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.
static int lastIndexOfSubList(List source, List target)
Returns the starting position of the last occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.
static ArrayList list(Enumeration e)
Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.
static T max(Collection coll)
       Returns the maximum element of the given collection, according to the natural ordering of its elements.

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

static >  T min(Collection coll)
Returns the minimum element of the given collection, according to the natural ordering of its elements.
static T min(Collection coll, Comparator comp)
Returns the minimum element of the given collection, according to the order induced by the specified comparator.
static List nCopies(int n, T o)
Returns an immutable list consisting of n copies of the specified object.
static Set newSetFromMap(Map map)
Returns a set backed by the specified map.
static boolean replaceAll(List list, T oldVal, T newVal)
Replaces all occurrences of one specified value in a list with another.
static void reverse(List list)
Reverses the order of the elements in the specified list.
static Comparator reverseOrder()
Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.
static Comparator reverseOrder(Comparator cmp)
Returns a comparator that imposes the reverse ordering of the specified comparator.
static void rotate(List list, int distance)
Rotates the elements in the specified list by the specified distance.
static void shuffle(List list)
Randomly permutes the specified list using a default source of randomness.
static void shuffle(List list, Random rnd)
Randomly permute the specified list using the specified source of randomness.
static Set singleton(T o)
Returns an immutable set containing only the specified object.
static List singletonList(T o)
Returns an immutable list containing only the specified object.
static Map singletonMap(K key, V value)
Returns an immutable map, mapping only the specified key to the specified value.
static void sort(List list)
Sorts the specified list into ascending order, according to the natural ordering of its elements.
static void sort(List list, Comparator c)
Sorts the specified list according to the order induced by the specified comparator.
static void swap(List list, int i, int j)
Swaps the elements at the specified positions in the specified list.
static Collection synchronizedCollection(Collection c)
Returns a synchronized (thread-safe) collection backed by the specified collection.
static List synchronizedList(List list)
Returns a synchronized (thread-safe) list backed by the specified list.
static Map synchronizedMap(Map m)
Returns a synchronized (thread-safe) map backed by the specified map.
static Set synchronizedSet(Set s)
Returns a synchronized (thread-safe) set backed by the specified set.
static SortedMap synchronizedSortedMap(SortedMap m)
Returns a synchronized (thread-safe) sorted map backed by the specified sorted map.
static SortedSet synchronizedSortedSet(SortedSet s)
Returns a synchronized (thread-safe) sorted set backed by the specified sorted set.
static Collection unmodifiableCollection(Collection c)
Returns an unmodifiable view of the specified collection.
static List unmodifiableList(List list)
Returns an unmodifiable view of the specified list.
static Map unmodifiableMap(Map m)
Returns an unmodifiable view of the specified map.
static Set unmodifiableSet(Set s)
Returns an unmodifiable view of the specified set.
static SortedMap unmodifiableSortedMap(SortedMap m)
Returns an unmodifiable view of the specified sorted map.
static SortedSet unmodifiableSortedSet(SortedSet s)
Returns an unmodifiable view of the specified sorted set.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Related Post

Comments


©candidjava.com