Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » util » [javadoc | source]
java.util
public class: Collections [javadoc | source]
java.lang.Object
   java.util.Collections
{@code Collections} contains static methods which operate on {@code Collection} classes.
Nested Class Summary:
static class  Collections.SynchronizedCollection   
static class  Collections.SynchronizedRandomAccessList   
static class  Collections.SynchronizedList   
static class  Collections.SynchronizedMap   
static class  Collections.SynchronizedSet   
static class  Collections.SynchronizedSortedMap   
static class  Collections.SynchronizedSortedSet   
Field Summary
public static final  List EMPTY_LIST    An empty immutable instance of List
public static final  Set EMPTY_SET    An empty immutable instance of Set
public static final  Map EMPTY_MAP    An empty immutable instance of Map
Method from java.util.Collections Summary:
addAll,   asLifoQueue,   binarySearch,   binarySearch,   checkType,   checkedCollection,   checkedList,   checkedMap,   checkedSet,   checkedSortedMap,   checkedSortedSet,   copy,   disjoint,   emptyList,   emptyMap,   emptySet,   enumeration,   fill,   frequency,   indexOfSubList,   lastIndexOfSubList,   list,   max,   max,   min,   min,   nCopies,   newSetFromMap,   replaceAll,   reverse,   reverseOrder,   reverseOrder,   rotate,   shuffle,   shuffle,   singleton,   singletonList,   singletonMap,   sort,   sort,   swap,   synchronizedCollection,   synchronizedList,   synchronizedMap,   synchronizedSet,   synchronizedSortedMap,   synchronizedSortedSet,   unmodifiableCollection,   unmodifiableList,   unmodifiableMap,   unmodifiableSet,   unmodifiableSortedMap,   unmodifiableSortedSet
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.util.Collections Detail:
 public static boolean addAll(Collection<? super T> c,
    T a) 
    Adds all the specified elements to the specified collection.
 public static Queue<T> asLifoQueue(Deque<T> deque) 
    Answers a LIFO Queue as a view of a Deque. Methods in the returned Queue need to be re-written to implement the LIFO feature.
 public static int binarySearch(List<Comparable> list,
    T object) 
    Performs a binary search for the specified element in the specified sorted list. The list needs to be already sorted in natural sorting order. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.
 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. The list needs to be already sorted according to the comparator passed. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.
 static E checkType(E obj,
    Class<? extends E> type) 
    Checks if specified object is instance of specified class. Used for a dynamically typesafe view of the collections.
 public static Collection<E> checkedCollection(Collection<E> c,
    Class<E> type) 
    Returns a dynamically typesafe view of the specified collection. Trying to insert an element of the wrong type into this collection throws a {@code ClassCastException}. At creation time the types in {@code c} are not checked for correct type.
 public static List<E> checkedList(List<E> list,
    Class<E> type) 
    Returns a dynamically typesafe view of the specified list. Trying to insert an element of the wrong type into this list throws a {@code ClassCastException}. At creation time the types in {@code list} are not checked for correct type.
 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. Trying to insert an element of the wrong type into this map throws a {@code ClassCastException}. At creation time the types in {@code m} are not checked for correct type.
 public static Set<E> checkedSet(Set<E> s,
    Class<E> type) 
    Returns a dynamically typesafe view of the specified set. Trying to insert an element of the wrong type into this set throws a {@code ClassCastException}. At creation time the types in {@code s} are not checked for correct type.
 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. Trying to insert an element of the wrong type into this sorted map throws a {@code ClassCastException}. At creation time the types in {@code m} are not checked for correct type.
 public static SortedSet<E> checkedSortedSet(SortedSet<E> s,
    Class<E> type) 
    Returns a dynamically typesafe view of the specified sorted set. Trying to insert an element of the wrong type into this sorted set throws a {@code ClassCastException}. At creation time the types in {@code s} are not checked for correct type.
 public static  void copy(List<? super T> destination,
    List<? extends T> source) 
    Copies the elements from the source list to the destination list. At the end both lists will have the same objects at the same index. If the destination array is larger than the source list, the elements in the destination list with {@code index >= source.size()} will be unchanged.
 public static boolean disjoint(Collection<?> c1,
    Collection<?> c2) 
    Returns whether the specified collections have no elements in common.
 public static final List<T> emptyList() 
    Returns a type-safe empty, immutable List .
 public static final Map<K, V> emptyMap() 
    Returns a type-safe empty, immutable Map .
 public static final Set<T> emptySet() 
    Returns a type-safe empty, immutable Set .
 public static Enumeration<T> enumeration(Collection<T> collection) 
    Returns an {@code 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 {@code Collection} that match the {@code Object} passed. If the {@code Object} is {@code null}, then the number of {@code null} elements is returned.
 public static int indexOfSubList(List<?> list,
    List<?> sublist) 
    Searches the {@code list} for {@code sublist} and returns the beginning index of the first occurrence.

    -1 is returned if the {@code sublist} does not exist in {@code list}.

 public static int lastIndexOfSubList(List<?> list,
    List<?> sublist) 
    Searches the {@code list} for {@code sublist} and returns the beginning index of the last occurrence.

    -1 is returned if the {@code sublist} does not exist in {@code list}.

 public static ArrayList<T> list(Enumeration<T> enumeration) 
    Returns an {@code ArrayList} with all the elements in the {@code enumeration}. The elements in the returned {@code ArrayList} are in the same order as in the {@code 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) 
    Returns a list containing the specified number of the specified element. The list cannot be modified. The list is serializable.
 public static Set<E> newSetFromMap(Map<E, Boolean> map) 
    Answers a set backed by a map. And the map must be empty when this method is called.
 public static boolean replaceAll(List<T> list,
    T obj,
    T obj2) 
    Replaces all occurrences of Object {@code obj} in {@code list} with {@code newObj}. If the {@code obj} is {@code null}, then all occurrences of {@code null} are replaced with {@code newObj}.
 public static  void reverse(List<?> list) 
    Modifies the specified {@code List} by reversing the order of the elements.
 public static Comparator<T> reverseOrder() 
    A comparator which reverses the natural order of the elements. The {@code Comparator} that's returned is Serializable .
 public static Comparator<T> reverseOrder(Comparator<T> c) 
    Returns a Comparator that reverses the order of the {@code Comparator} passed. If the {@code Comparator} passed is {@code null}, then this method is equivalent to #reverseOrder() .

    The {@code Comparator} that's returned is Serializable if the {@code Comparator} passed is serializable or {@code null}.

 public static  void rotate(List<?> lst,
    int dist) 
    Rotates the elements in {@code list} by the distance {@code 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]

 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) 
    Returns a set containing the specified element. The set cannot be modified. The set is serializable.
 public static List<E> singletonList(E object) 
    Returns a list containing the specified element. The list cannot be modified. The list is serializable.
 public static Map<K, V> singletonMap(K key,
    V value) 
    Returns a Map containing the specified key and value. The map cannot be modified. The map is serializable.
 public static  void sort(List<T> list) 
    Sorts the specified list in ascending natural order. The algorithm is stable which means equal elements don't get reordered.
 public static  void sort(List<T> list,
    Comparator<? super T> comparator) 
    Sorts the specified list using the specified comparator. The algorithm is stable which means equal elements don't get reordered.
 public static  void swap(List<?> list,
    int index1,
    int index2) 
    Swaps the elements of list {@code list} at indices {@code index1} and {@code index2}.
 public static Collection<T> synchronizedCollection(Collection<T> collection) 
    Returns a wrapper on the specified collection which synchronizes all access to the collection.
 public static List<T> synchronizedList(List<T> list) 
    Returns a wrapper on the specified List which synchronizes all access to the List.
 public static Map<K, V> synchronizedMap(Map<K, V> map) 
    Returns a wrapper on the specified map which synchronizes all access to the map.
 public static Set<E> synchronizedSet(Set<E> set) 
    Returns a wrapper on the specified set which synchronizes all access to the set.
 public static SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> map) 
    Returns a wrapper on the specified sorted map which synchronizes all access to the sorted map.
 public static SortedSet<E> synchronizedSortedSet(SortedSet<E> set) 
    Returns a wrapper on the specified sorted set which synchronizes all access to the sorted set.
 public static Collection<E> unmodifiableCollection(Collection<? extends E> collection) 
    Returns a wrapper on the specified collection which throws an {@code UnsupportedOperationException} whenever an attempt is made to modify the collection.
 public static List<E> unmodifiableList(List<? extends E> list) 
    Returns a wrapper on the specified list which throws an {@code UnsupportedOperationException} whenever an attempt is made to modify the list.
 public static Map<K, V> unmodifiableMap(Map<? extends K, ? extends V> map) 
    Returns a wrapper on the specified map which throws an {@code UnsupportedOperationException} whenever an attempt is made to modify the map.
 public static Set<E> unmodifiableSet(Set<? extends E> set) 
    Returns a wrapper on the specified set which throws an {@code UnsupportedOperationException} whenever an attempt is made to modify the set.
 public static SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, ? extends V> map) 
    Returns a wrapper on the specified sorted map which throws an {@code UnsupportedOperationException} whenever an attempt is made to modify the sorted map.
 public static SortedSet<E> unmodifiableSortedSet(SortedSet<E> set) 
    Returns a wrapper on the specified sorted set which throws an {@code UnsupportedOperationException} whenever an attempt is made to modify the sorted set.