| java.lang.Object java.util.Collections
Collections | public class Collections (Code) | | Collections contains static methods which operate on Collection classes.
since: 1.2 |
Inner Class :static class SynchronizedRandomAccessList extends SynchronizedList implements RandomAccess | |
Inner Class :static class SynchronizedList extends SynchronizedCollection implements List<E> | |
Inner Class :static class SynchronizedMap implements Map<K, V>,Serializable | |
Inner Class :static class SynchronizedSet extends SynchronizedCollection implements Set<E> | |
Inner Class :static class SynchronizedSortedMap extends SynchronizedMap implements SortedMap<K, V> | |
Inner Class :static class SynchronizedSortedSet extends SynchronizedSet implements SortedSet<E> | |
Field Summary | |
final public static List | EMPTY_LIST An immutable, serializable, empty List . | final public static Map | EMPTY_MAP An immutable, serializable, empty Map . | final public static Set | EMPTY_SET An immutable, serializable, empty Set . |
Method Summary | |
public static boolean | addAll(Collection<? super T> c, T... a) | public static int | binarySearch(List<? extends Comparable<? super T>> list, T object) Performs a binary search for the specified element in the specified
sorted List. | public static int | binarySearch(List<? extends T> list, T object, Comparator<? super T> comparator) Performs a binary search for the specified element in the specified
sorted List using the specified Comparator.
< Parameters: T - > The element type Parameters: list - the sorted List to search Parameters: object - the element to find Parameters: comparator - the Comparator. | static E | checkType(E obj, Class<E> type) Checks if specified object is instance of specified class. | public static Collection<E> | checkedCollection(Collection<E> c, Class<E> type) Returns a dynamically typesafe view of the specified collection. | public static List<E> | checkedList(List<E> list, Class<E> type) Returns a dynamically typesafe view of the specified list. | public static Map<K, V> | checkedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType) Returns a dynamically typesafe view of the specified map. | public static Set<E> | checkedSet(Set<E> s, Class<E> type) Returns a dynamically typesafe view of the specified set. | public static SortedMap<K, V> | checkedSortedMap(SortedMap<K, V> m, Class<K> keyType, Class<V> valueType) Returns a dynamically typesafe view of the specified sorted map. | public static SortedSet<E> | checkedSortedSet(SortedSet<E> s, Class<E> type) Returns a dynamically typesafe view of the specified sorted set. | public static void | copy(List<? super T> destination, List<? extends T> source) Copies the elements from the source list to the destination list. | public static boolean | disjoint(Collection> c1, Collection> c2) | final public static List<T> | emptyList() Returns a type-safe empty, immutable
List . | final public static Map<K, V> | emptyMap() Returns a type-safe empty, immutable
Map . | final public static Set<T> | emptySet() Returns a type-safe empty, immutable
Set . | public static Enumeration<T> | enumeration(Collection<T> collection) Answers an Enumeration on the specified Collection. | public static void | fill(List<? super T> list, T object) Fills the specified List with the specified element. | public static int | frequency(Collection> c, Object o)
Returns the number of elements in the Collection that
match the Object passed. | public static int | indexOfSubList(List> list, List> sublist) Searches the list for sublist and answers
the beginning index of the first occurrence. | public static int | lastIndexOfSubList(List> list, List> sublist) Searches the list for sublist and answers
the beginning index of the last occurrence. | public static ArrayList<T> | list(Enumeration<T> enumeration) Answers an ArrayList with all the elements in the
enumeration . | public static T | max(Collection<? extends T> collection) Searches the specified Collection for the maximum element. | public static T | max(Collection<? extends T> collection, Comparator<? super T> comparator) Searches the specified Collection for the maximum element using the
specified Comparator. | public static T | min(Collection<? extends T> collection) Searches the specified Collection for the minimum element. | public static T | min(Collection<? extends T> collection, Comparator<? super T> comparator) Searches the specified Collection for the minimum element using the
specified Comparator. | public static List<T> | nCopies(int length, T object) Answers a List containing the specified number of the specified element. | public static boolean | replaceAll(List<T> list, T obj, T obj2) Replaces all occurrences of Object obj in
list with newObj . | public static void | reverse(List> list) Returns the supplied List with the order of its contained
elements reversed. | public static Comparator<T> | reverseOrder()
A Comparator which reverses the natural order of the elements. | public static Comparator<T> | reverseOrder(Comparator<T> c)
Returns a
Comparator that reverses the order of the
Comparator passed. | public static void | rotate(List> lst, int dist) Rotates the elements in List list by the distance
dist
e.g. | public static void | shuffle(List> list) Moves every element of the List to a random new position in the list. | public static void | shuffle(List> list, Random random) Moves every element of the List to a random new position in the list
using the specified random number generator. | public static Set<E> | singleton(E object) Answers a Set containing the specified element. | public static List<E> | singletonList(E object) Answers a List containing the specified element. | public static Map<K, V> | singletonMap(K key, V value) Answers a Map containing the specified key and value. | public static void | sort(List<T> list) Sorts the specified List in ascending order. | public static void | sort(List<T> list, Comparator<? super T> comparator) Sorts the specified List using the specified Comparator. | public static void | swap(List> list, int index1, int index2) | public static Collection<T> | synchronizedCollection(Collection<T> collection) Answers a wrapper on the specified Collection which synchronizes all
access to the Collection. | public static List<T> | synchronizedList(List<T> list) Answers a wrapper on the specified List which synchronizes all access to
the List. | public static Map<K, V> | synchronizedMap(Map<K, V> map) Answers a wrapper on the specified Map which synchronizes all access to
the Map. | public static Set<E> | synchronizedSet(Set<E> set) Answers a wrapper on the specified Set which synchronizes all access to
the Set. | public static SortedMap<K, V> | synchronizedSortedMap(SortedMap<K, V> map) Answers a wrapper on the specified SortedMap which synchronizes all
access to the SortedMap. | public static SortedSet<E> | synchronizedSortedSet(SortedSet<E> set) Answers a wrapper on the specified SortedSet which synchronizes all
access to the SortedSet. | public static Collection<E> | unmodifiableCollection(Collection<? extends E> collection) Answers a wrapper on the specified Collection which throws an
UnsupportedOperationException whenever an attempt is made
to modify the Collection. | public static List<E> | unmodifiableList(List<? extends E> list) Answers a wrapper on the specified List which throws an
UnsupportedOperationException whenever an attempt is made
to modify the List. | public static Map<K, V> | unmodifiableMap(Map<? extends K, ? extends V> map) Answers a wrapper on the specified Map which throws an
UnsupportedOperationException whenever an attempt is made
to modify the Map. | public static Set<E> | unmodifiableSet(Set<? extends E> set) Answers a wrapper on the specified Set which throws an
UnsupportedOperationException whenever an attempt is made
to modify the Set. | public static SortedMap<K, V> | unmodifiableSortedMap(SortedMap<K, ? extends V> map) Answers a wrapper on the specified SortedMap which throws an
UnsupportedOperationException whenever an attempt is made
to modify the SortedMap. | public static SortedSet<E> | unmodifiableSortedSet(SortedSet<E> set) Answers a wrapper on the specified SortedSet which throws an
UnsupportedOperationException whenever an attempt is made
to modify the SortedSet. |
addAll | public static boolean addAll(Collection<? super T> c, T... a)(Code) | | Adds all the specified elements to the specified collection
Parameters: c - the collection the elements are to be inserted into Parameters: a - the elements to insert true if the collection changed during insertion throws: UnsupportedOperationException - when the method is not supported throws: NullPointerException - when c or elements is null, or elements contains one or morenull elements and c doesn't support null elements |
binarySearch | public static int binarySearch(List<? extends Comparable<? super T>> list, T object)(Code) | | Performs a binary search for the specified element in the specified
sorted List.
Parameters: list - the sorted List to search Parameters: object - the element to find the non-negative index of the element, or a negative index whichis the -index - 1 where the element would be inserted throws: ClassCastException - when an element in the List or the search element does notimplement Comparable, or cannot be compared to each other |
binarySearch | public static int binarySearch(List<? extends T> list, T object, Comparator<? super T> comparator)(Code) | | Performs a binary search for the specified element in the specified
sorted List using the specified Comparator.
< Parameters: T - > The element type Parameters: list - the sorted List to search Parameters: object - the element to find Parameters: comparator - the Comparator. If the comparator is null thenthe search uses the objects' natural ordering. the non-negative index of the element, or a negative index whichis the -index - 1 where the element would be inserted throws: ClassCastException - when an element in the list and the searched element cannotbe compared to each other using the Comparator |
checkType | static E checkType(E obj, Class<E> type)(Code) | | Checks if specified object is instance of specified class. Used for a
dynamically typesafe view of the collections.
Parameters: obj - -object is to be checked Parameters: type - -class of object that should be specified object |
checkedCollection | public static Collection<E> checkedCollection(Collection<E> c, Class<E> type)(Code) | | Returns a dynamically typesafe view of the specified collection.
Parameters: c - the collection Parameters: type - the type of the elements is permitted to insert a typesafe collection |
checkedList | public static List<E> checkedList(List<E> list, Class<E> type)(Code) | | Returns a dynamically typesafe view of the specified list.
Parameters: list - the list Parameters: type - the type of the elements is permitted to insert a typesafe list |
checkedMap | public static Map<K, V> checkedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType)(Code) | | Returns a dynamically typesafe view of the specified map.
Parameters: m - the map Parameters: keyType - the type of keys permitted to be inserted Parameters: valueType - the type of values permitted to be inserted a typesafe map |
checkedSet | public static Set<E> checkedSet(Set<E> s, Class<E> type)(Code) | | Returns a dynamically typesafe view of the specified set.
Parameters: s - the set Parameters: type - the type of the elements is permitted to insert a typesafe set |
checkedSortedMap | public static SortedMap<K, V> checkedSortedMap(SortedMap<K, V> m, Class<K> keyType, Class<V> valueType)(Code) | | Returns a dynamically typesafe view of the specified sorted map.
Parameters: m - the sorted map Parameters: keyType - the type of keys permitted to be inserted Parameters: valueType - the type of values permitted to be inserted a typesafe sorted map |
checkedSortedSet | public static SortedSet<E> checkedSortedSet(SortedSet<E> s, Class<E> type)(Code) | | Returns a dynamically typesafe view of the specified sorted set.
Parameters: s - the sorted set Parameters: type - the type of the elements is permitted to insert a typesafe sorted set |
copy | public static void copy(List<? super T> destination, List<? extends T> source)(Code) | | Copies the elements from the source list to the destination list.
Parameters: destination - Parameters: source - throws: IndexOutOfBoundsException - when the destination List is smaller than the source List throws: UnsupportedOperationException - when replacing an element in the destination list is notsupported |
disjoint | public static boolean disjoint(Collection> c1, Collection> c2)(Code) | | Returns true if the collections have no elements in common
Parameters: c1 - the first collection Parameters: c2 - the second collection true if the collections have no elements in common throws: NullPointerException - if one of the collections is null |
enumeration | public static Enumeration<T> enumeration(Collection<T> collection)(Code) | | Answers an Enumeration on the specified Collection.
Parameters: collection - the Collection to enumerate an Enumeration |
fill | public static void fill(List<? super T> list, T object)(Code) | | Fills the specified List with the specified element.
Parameters: list - the List to fill Parameters: object - the fill element throws: UnsupportedOperationException - when replacing an element in the List is not supported |
frequency | public static int frequency(Collection> c, Object o)(Code) | |
Returns the number of elements in the Collection that
match the Object passed. If the Object is
null , then the number of null elements is
returned.
Parameters: c - The Collection to search. Parameters: o - The Object to search for. The number of matching elements. throws: NullPointerException - if the Collection parameter isnull . since: 1.5 |
indexOfSubList | public static int indexOfSubList(List> list, List> sublist)(Code) | | Searches the list for sublist and answers
the beginning index of the first occurrence.
-1 is returned if the sublist does not exist in
list
Parameters: list - the List to search sublist in Parameters: sublist - the List to search in list the beginning index of the first occurrence ofsublist in list , or -1 |
lastIndexOfSubList | public static int lastIndexOfSubList(List> list, List> sublist)(Code) | | Searches the list for sublist and answers
the beginning index of the last occurrence.
-1 is returned if the sublist does not exist in
list
Parameters: list - the List to search sublist in Parameters: sublist - the List to search in list the beginning index of the last occurrence ofsublist in list , or -1 |
list | public static ArrayList<T> list(Enumeration<T> enumeration)(Code) | | Answers an ArrayList with all the elements in the
enumeration . The elements in the returned ArrayList are
in the same order as in the enumeration .
Parameters: enumeration - Enumeration and ArrayList |
max | public static T max(Collection<? extends T> collection)(Code) | | Searches the specified Collection for the maximum element.
Parameters: collection - the Collection to search the maximum element in the Collection throws: ClassCastException - when an element in the Collection does not implementComparable or elements cannot be compared to each other |
max | public static T max(Collection<? extends T> collection, Comparator<? super T> comparator)(Code) | | Searches the specified Collection for the maximum element using the
specified Comparator.
Parameters: collection - the Collection to search Parameters: comparator - the Comparator the maximum element in the Collection throws: ClassCastException - when elements in the Collection cannot be compared to eachother using the Comparator |
min | public static T min(Collection<? extends T> collection)(Code) | | Searches the specified Collection for the minimum element.
Parameters: collection - the Collection to search the minimum element in the Collection throws: ClassCastException - when an element in the Collection does not implementComparable or elements cannot be compared to each other |
min | public static T min(Collection<? extends T> collection, Comparator<? super T> comparator)(Code) | | Searches the specified Collection for the minimum element using the
specified Comparator.
Parameters: collection - the Collection to search Parameters: comparator - the Comparator the minimum element in the Collection throws: ClassCastException - when elements in the Collection cannot be compared to eachother using the Comparator |
nCopies | public static List<T> nCopies(int length, T object)(Code) | | Answers a List containing the specified number of the specified element.
The list cannot be modified.
Parameters: length - the size of the returned List Parameters: object - the element a List containing length copies of the element throws: IllegalArgumentException - when length < 0 |
replaceAll | public static boolean replaceAll(List<T> list, T obj, T obj2)(Code) | | Replaces all occurrences of Object obj in
list with newObj . If the obj
is null , then all occurrences of null is
replaced with newObj .
Parameters: list - the List to modify Parameters: obj - the Object to find and replace occurrences of. Parameters: obj2 - the Object to replace all occurrences of obj inlist true, if at least one occurrence of obj has beenfound in list throws: UnsupportedOperationException - if the list does not support setting elements |
reverse | public static void reverse(List> list)(Code) | | Returns the supplied List with the order of its contained
elements reversed.
Parameters: list - the List to reverse throws: UnsupportedOperationException - when replacing an element in the List is not supported |
reverseOrder | public static Comparator<T> reverseOrder(Comparator<T> c)(Code) | |
Returns a
Comparator that reverses the order of the
Comparator passed. If the Comparator passed
is null , then this method is equivalent to
Collections.reverseOrder() .
The Comparator that's returned is
Serializable if
the Comparator passed is serializable or null .
Parameters: c - The Comparator to reverse or null . A Comparator instance. See Also: Comparator since: 1.5 |
rotate | public static void rotate(List> lst, int dist)(Code) | | Rotates the elements in List list by the distance
dist
e.g. for a given list with elements [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
calling rotate(list, 3) or rotate(list, -7) would modify the list to look
like this: [8, 9, 0, 1, 2, 3, 4, 5, 6, 7]
Parameters: lst - Parameters: dist - It can be any integer: 0, positive, negative, larger than thelist size |
shuffle | public static void shuffle(List> list)(Code) | | Moves every element of the List to a random new position in the list.
Parameters: list - the List to shuffle throws: UnsupportedOperationException - when replacing an element in the List is not supported |
shuffle | public static void shuffle(List> list, Random random)(Code) | | Moves every element of the List to a random new position in the list
using the specified random number generator.
Parameters: list - the List to shuffle Parameters: random - the random number generator throws: UnsupportedOperationException - when replacing an element in the List is not supported |
singleton | public static Set<E> singleton(E object)(Code) | | Answers a Set containing the specified element. The set cannot be
modified.
Parameters: object - the element a Set containing the element |
singletonList | public static List<E> singletonList(E object)(Code) | | Answers a List containing the specified element. The list cannot be
modified.
Parameters: object - the element a List containing the element |
singletonMap | public static Map<K, V> singletonMap(K key, V value)(Code) | | Answers a Map containing the specified key and value. The map cannot be
modified.
Parameters: key - the key Parameters: value - the value a Map containing the key and value |
sort | public static void sort(List<T> list)(Code) | | Sorts the specified List in ascending order.
Parameters: list - the List to be sorted throws: ClassCastException - when an element in the List does not implement Comparable orelements cannot be compared to each other |
sort | public static void sort(List<T> list, Comparator<? super T> comparator)(Code) | | Sorts the specified List using the specified Comparator.
Parameters: list - the List to be sorted Parameters: comparator - the Comparator throws: ClassCastException - when elements in the List cannot be compared to each otherusing the Comparator |
swap | public static void swap(List> list, int index1, int index2)(Code) | | Swaps the elements of List list at indices
index1 and index2
Parameters: list - the List to manipulate on Parameters: index1 - int position of the first element to swap with the element inindex2 Parameters: index2 - int position of the other element throws: IndexOutOfBoundsException - if index1 or index2 is out of range of this list |
synchronizedCollection | public static Collection<T> synchronizedCollection(Collection<T> collection)(Code) | | Answers a wrapper on the specified Collection which synchronizes all
access to the Collection.
Parameters: collection - the Collection a synchronized Collection |
synchronizedList | public static List<T> synchronizedList(List<T> list)(Code) | | Answers a wrapper on the specified List which synchronizes all access to
the List.
Parameters: list - the List a synchronized List |
synchronizedMap | public static Map<K, V> synchronizedMap(Map<K, V> map)(Code) | | Answers a wrapper on the specified Map which synchronizes all access to
the Map.
Parameters: map - the Map a synchronized Map |
synchronizedSet | public static Set<E> synchronizedSet(Set<E> set)(Code) | | Answers a wrapper on the specified Set which synchronizes all access to
the Set.
Parameters: set - the Set a synchronized Set |
synchronizedSortedMap | public static SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> map)(Code) | | Answers a wrapper on the specified SortedMap which synchronizes all
access to the SortedMap.
Parameters: map - the SortedMap a synchronized SortedMap |
synchronizedSortedSet | public static SortedSet<E> synchronizedSortedSet(SortedSet<E> set)(Code) | | Answers a wrapper on the specified SortedSet which synchronizes all
access to the SortedSet.
Parameters: set - the SortedSet a synchronized SortedSet |
unmodifiableCollection | public static Collection<E> unmodifiableCollection(Collection<? extends E> collection)(Code) | | Answers a wrapper on the specified Collection which throws an
UnsupportedOperationException whenever an attempt is made
to modify the Collection.
Parameters: collection - the Collection an unmodifiable Collection |
unmodifiableList | public static List<E> unmodifiableList(List<? extends E> list)(Code) | | Answers a wrapper on the specified List which throws an
UnsupportedOperationException whenever an attempt is made
to modify the List.
Parameters: list - the List an unmodifiable List |
unmodifiableMap | public static Map<K, V> unmodifiableMap(Map<? extends K, ? extends V> map)(Code) | | Answers a wrapper on the specified Map which throws an
UnsupportedOperationException whenever an attempt is made
to modify the Map.
Parameters: map - the Map a unmodifiable Map |
unmodifiableSet | public static Set<E> unmodifiableSet(Set<? extends E> set)(Code) | | Answers a wrapper on the specified Set which throws an
UnsupportedOperationException whenever an attempt is made
to modify the Set.
Parameters: set - the Set a unmodifiable Set |
unmodifiableSortedMap | public static SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, ? extends V> map)(Code) | | Answers a wrapper on the specified SortedMap which throws an
UnsupportedOperationException whenever an attempt is made
to modify the SortedMap.
Parameters: map - the SortedMap a unmodifiable SortedMap |
unmodifiableSortedSet | public static SortedSet<E> unmodifiableSortedSet(SortedSet<E> set)(Code) | | Answers a wrapper on the specified SortedSet which throws an
UnsupportedOperationException whenever an attempt is made
to modify the SortedSet.
Parameters: set - the SortedSet a unmodifiable SortedSet |
|
|