|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.Collections
public class Collections
Collections contains static methods which operate on Collection classes.
| Nested Class Summary | |
|---|---|
(package private) static class |
Collections.SynchronizedCollection<E>
|
(package private) static class |
Collections.SynchronizedList<E>
|
(package private) static class |
Collections.SynchronizedMap<K,V>
|
(package private) static class |
Collections.SynchronizedRandomAccessList<E>
|
(package private) static class |
Collections.SynchronizedSet<E>
|
(package private) static class |
Collections.SynchronizedSortedMap<K,V>
|
(package private) static class |
Collections.SynchronizedSortedSet<E>
|
| Field Summary | |
|---|---|
static List |
EMPTY_LIST
|
static Map |
EMPTY_MAP
|
static Set |
EMPTY_SET
|
| Method Summary | ||
|---|---|---|
static
|
addAll(Collection<? super T> c,
T... a)
Adds all the specified elements to the specified collection |
|
static
|
binarySearch(List<? extends Comparable<? super T>> list,
T object)
Performs a binary search for the specified element in the specified sorted List. |
|
static
|
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. |
|
static
|
checkedCollection(Collection<E> c,
Class<E> type)
Returns a dynamically typesafe view of the specified collection. |
|
static
|
checkedList(List<E> list,
Class<E> type)
Returns a dynamically typesafe view of the specified list. |
|
static
|
checkedMap(Map<K,V> m,
Class<K> keyType,
Class<V> valueType)
Returns a dynamically typesafe view of the specified map. |
|
static
|
checkedSet(Set<E> s,
Class<E> type)
Returns a dynamically typesafe view of the specified set. |
|
static
|
checkedSortedMap(SortedMap<K,V> m,
Class<K> keyType,
Class<V> valueType)
Returns a dynamically typesafe view of the specified sorted map. |
|
static
|
checkedSortedSet(SortedSet<E> s,
Class<E> type)
Returns a dynamically typesafe view of the specified sorted set. |
|
(package private) static
|
checkType(E obj,
Class<E> type)
Checks if specified object is instance of specified class. |
|
static
|
copy(List<? super T> destination,
List<? extends T> source)
Copies the elements from the source list to the destination list. |
|
static boolean |
disjoint(Collection<?> c1,
Collection<?> c2)
Returns true if the collections have no elements in common |
|
static
|
emptyList()
Returns a type-safe empty, immutable List. |
|
static
|
emptyMap()
Returns a type-safe empty, immutable Map. |
|
static
|
emptySet()
Returns a type-safe empty, immutable Set. |
|
static
|
enumeration(Collection<T> collection)
Returns an Enumeration on the specified Collection. |
|
static
|
fill(List<? super T> list,
T object)
Fills the specified List with the specified element. |
|
static int |
frequency(Collection<?> c,
Object o)
Returns the number of elements in the Collection that
match the Object passed. |
|
static int |
indexOfSubList(List<?> list,
List<?> sublist)
Searches the list for sublist and returns
the beginning index of the first occurrence. |
|
static int |
lastIndexOfSubList(List<?> list,
List<?> sublist)
Searches the list for sublist and returns
the beginning index of the last occurrence. |
|
static
|
list(Enumeration<T> enumeration)
Returns an ArrayList with all the elements in the enumeration. |
|
static
|
max(Collection<? extends T> collection)
Searches the specified Collection for the maximum element. |
|
static
|
max(Collection<? extends T> collection,
Comparator<? super T> comparator)
Searches the specified Collection for the maximum element using the specified Comparator. |
|
static
|
min(Collection<? extends T> collection)
Searches the specified Collection for the minimum element. |
|
static
|
min(Collection<? extends T> collection,
Comparator<? super T> comparator)
Searches the specified Collection for the minimum element using the specified Comparator. |
|
static
|
nCopies(int length,
T object)
Returns a List containing the specified number of the specified element. |
|
static
|
replaceAll(List<T> list,
T obj,
T obj2)
Replaces all occurrences of Object obj in
list with newObj. |
|
static void |
reverse(List<?> list)
Returns the supplied List with the order of its contained
elements reversed. |
|
static
|
reverseOrder()
A Comparator which reverses the natural order of the elements. |
|
static
|
reverseOrder(Comparator<T> c)
Returns a Comparator that reverses the order of the
Comparator passed. |
|
static void |
rotate(List<?> lst,
int dist)
Rotates the elements in List list by the distance
dist |
|
static void |
shuffle(List<?> list)
Moves every element of the List to a random new position in the list. |
|
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. |
|
static
|
singleton(E object)
Returns a Set containing the specified element. |
|
static
|
singletonList(E object)
Returns a List containing the specified element. |
|
static
|
singletonMap(K key,
V value)
Returns a Map containing the specified key and value. |
|
static
|
sort(List<T> list)
Sorts the specified List in ascending order. |
|
static
|
sort(List<T> list,
Comparator<? super T> comparator)
Sorts the specified List using the specified Comparator. |
|
static void |
swap(List<?> list,
int index1,
int index2)
Swaps the elements of List list at indices
index1 and index2 |
|
static
|
synchronizedCollection(Collection<T> collection)
Returns a wrapper on the specified Collection which synchronizes all access to the Collection. |
|
static
|
synchronizedList(List<T> list)
Returns a wrapper on the specified List which synchronizes all access to the List. |
|
static
|
synchronizedMap(Map<K,V> map)
Returns a wrapper on the specified Map which synchronizes all access to the Map. |
|
static
|
synchronizedSet(Set<E> set)
Returns a wrapper on the specified Set which synchronizes all access to the Set. |
|
static
|
synchronizedSortedMap(SortedMap<K,V> map)
Returns a wrapper on the specified SortedMap which synchronizes all access to the SortedMap. |
|
static
|
synchronizedSortedSet(SortedSet<E> set)
Returns a wrapper on the specified SortedSet which synchronizes all access to the SortedSet. |
|
static
|
unmodifiableCollection(Collection<? extends E> collection)
Returns a wrapper on the specified Collection which throws an UnsupportedOperationException whenever an attempt is made
to modify the Collection. |
|
static
|
unmodifiableList(List<? extends E> list)
Returns a wrapper on the specified List which throws an UnsupportedOperationException whenever an attempt is made
to modify the List. |
|
static
|
unmodifiableMap(Map<? extends K,? extends V> map)
Returns a wrapper on the specified Map which throws an UnsupportedOperationException whenever an attempt is made
to modify the Map. |
|
static
|
unmodifiableSet(Set<? extends E> set)
Returns a wrapper on the specified Set which throws an UnsupportedOperationException whenever an attempt is made
to modify the Set. |
|
static
|
unmodifiableSortedMap(SortedMap<K,? extends V> map)
Returns a wrapper on the specified SortedMap which throws an UnsupportedOperationException whenever an attempt is made
to modify the SortedMap. |
|
static
|
unmodifiableSortedSet(SortedSet<E> set)
Returns a wrapper on the specified SortedSet which throws an UnsupportedOperationException whenever an attempt is made
to modify the SortedSet. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final List EMPTY_LIST
public static final Set EMPTY_SET
public static final Map EMPTY_MAP
| Method Detail |
|---|
public static <T> int binarySearch(List<? extends Comparable<? super T>> list,
T object)
list - the sorted List to searchobject - the element to find
ClassCastException - when an element in the List or the search element does not
implement Comparable, or cannot be compared to each other
public static <T> int binarySearch(List<? extends T> list,
T object,
Comparator<? super T> comparator)
list - the sorted List to searchobject - the element to findcomparator - the Comparator. If the comparator is null then
the search uses the objects' natural ordering.
ClassCastException - when an element in the list and the searched element cannot
be compared to each other using the Comparator
public static <T> void copy(List<? super T> destination,
List<? extends T> source)
destination - source -
IndexOutOfBoundsException - when the destination List is smaller than the source List
UnsupportedOperationException - when replacing an element in the destination list is not
supportedpublic static <T> Enumeration<T> enumeration(Collection<T> collection)
collection - the Collection to enumerate
public static <T> void fill(List<? super T> list,
T object)
list - the List to fillobject - the fill element
UnsupportedOperationException - when replacing an element in the List is not supportedpublic static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> collection)
collection - the Collection to search
ClassCastException - when an element in the Collection does not implement
Comparable or elements cannot be compared to each other
public static <T> T max(Collection<? extends T> collection,
Comparator<? super T> comparator)
collection - the Collection to searchcomparator - the Comparator
ClassCastException - when elements in the Collection cannot be compared to each
other using the Comparatorpublic static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> collection)
collection - the Collection to search
ClassCastException - when an element in the Collection does not implement
Comparable or elements cannot be compared to each other
public static <T> T min(Collection<? extends T> collection,
Comparator<? super T> comparator)
collection - the Collection to searchcomparator - the Comparator
ClassCastException - when elements in the Collection cannot be compared to each
other using the Comparator
public static <T> List<T> nCopies(int length,
T object)
length - the size of the returned Listobject - the element
length copies of the element
IllegalArgumentException - when length < 0public static void reverse(List<?> list)
List with the order of its contained
elements reversed.
list - the List to reverse
UnsupportedOperationException - when replacing an element in the List is not supportedpublic static <T> Comparator<T> reverseOrder()
A Comparator which reverses the natural order of the elements. The
Comparator that's returned is Serializable.
Comparator instance.Comparator,
Comparable,
Serializablepublic static <T> Comparator<T> reverseOrder(Comparator<T> c)
Returns a Comparator that reverses the order of the
Comparator passed. If the Comparator passed
is null, then this method is equivalent to
reverseOrder().
The Comparator that's returned is Serializable if
the Comparator passed is serializable or null.
c - The Comparator to reverse or null.
Comparator instance.Comparatorpublic static void shuffle(List<?> list)
list - the List to shuffle
UnsupportedOperationException - when replacing an element in the List is not supported
public static void shuffle(List<?> list,
Random random)
list - the List to shufflerandom - the random number generator
UnsupportedOperationException - when replacing an element in the List is not supportedpublic static <E> Set<E> singleton(E object)
object - the element
public static <E> List<E> singletonList(E object)
object - the element
public static <K,V> Map<K,V> singletonMap(K key,
V value)
key - the keyvalue - the value
public static <T extends Comparable<? super T>> void sort(List<T> list)
list - the List to be sorted
ClassCastException - when an element in the List does not implement Comparable or
elements cannot be compared to each other
public static <T> void sort(List<T> list,
Comparator<? super T> comparator)
list - the List to be sortedcomparator - the Comparator
ClassCastException - when elements in the List cannot be compared to each other
using the Comparator
public static void swap(List<?> list,
int index1,
int index2)
list at indices
index1 and index2
list - the List to manipulate onindex1 - int position of the first element to swap with the element in
index2index2 - int position of the other element
IndexOutOfBoundsException - if index1 or index2 is out of range of this list
public static <T> boolean replaceAll(List<T> list,
T obj,
T obj2)
obj in
list with newObj. If the obj
is null, then all occurrences of null is
replaced with newObj.
list - the List to modifyobj - the Object to find and replace occurrences of.obj2 - the Object to replace all occurrences of obj in
list
obj has been
found in list
UnsupportedOperationException - if the list does not support setting elements
public static void rotate(List<?> lst,
int dist)
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]
lst - dist - It can be any integer: 0, positive, negative, larger than the
list size
public static int indexOfSubList(List<?> list,
List<?> sublist)
list for sublist and returns
the beginning index of the first occurrence.
-1 is returned if the sublist does not exist in
list
list - the List to search sublist insublist - the List to search in list
sublist in list, or -1
public static int lastIndexOfSubList(List<?> list,
List<?> sublist)
list for sublist and returns
the beginning index of the last occurrence.
-1 is returned if the sublist does not exist in
list
list - the List to search sublist insublist - the List to search in list
sublist in list, or -1public static <T> ArrayList<T> list(Enumeration<T> enumeration)
enumeration. The elements in the returned ArrayList are
in the same order as in the enumeration.
enumeration - Enumeration
public static <T> Collection<T> synchronizedCollection(Collection<T> collection)
collection - the Collection
public static <T> List<T> synchronizedList(List<T> list)
list - the List
public static <K,V> Map<K,V> synchronizedMap(Map<K,V> map)
map - the Map
public static <E> Set<E> synchronizedSet(Set<E> set)
set - the Set
public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> map)
map - the SortedMap
public static <E> SortedSet<E> synchronizedSortedSet(SortedSet<E> set)
set - the SortedSet
public static <E> Collection<E> unmodifiableCollection(Collection<? extends E> collection)
UnsupportedOperationException whenever an attempt is made
to modify the Collection.
collection - the Collection
public static <E> List<E> unmodifiableList(List<? extends E> list)
UnsupportedOperationException whenever an attempt is made
to modify the List.
list - the List
public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K,? extends V> map)
UnsupportedOperationException whenever an attempt is made
to modify the Map.
map - the Map
public static <E> Set<E> unmodifiableSet(Set<? extends E> set)
UnsupportedOperationException whenever an attempt is made
to modify the Set.
set - the Set
public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K,? extends V> map)
UnsupportedOperationException whenever an attempt is made
to modify the SortedMap.
map - the SortedMap
public static <E> SortedSet<E> unmodifiableSortedSet(SortedSet<E> set)
UnsupportedOperationException whenever an attempt is made
to modify the SortedSet.
set - the SortedSet
public static int frequency(Collection<?> c,
Object o)
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.
c - The Collection to search.o - The Object to search for.
NullPointerException - if the Collection parameter is
null.public static final <T> List<T> emptyList()
List.
List.EMPTY_LISTpublic static final <T> Set<T> emptySet()
Set.
Set.EMPTY_SETpublic static final <K,V> Map<K,V> emptyMap()
Map.
Map.EMPTY_MAP
public static <E> Collection<E> checkedCollection(Collection<E> c,
Class<E> type)
c - the collectiontype - the type of the elements permitted to insert
public static <K,V> Map<K,V> checkedMap(Map<K,V> m,
Class<K> keyType,
Class<V> valueType)
m - the mapkeyType - the type of the keys permitted to insertvalueType - the type of the values permitted to insert
public static <E> List<E> checkedList(List<E> list,
Class<E> type)
list - the listtype - the type of the elements permitted to insert
public static <E> Set<E> checkedSet(Set<E> s,
Class<E> type)
s - the settype - the type of the elements permitted to insert
public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K,V> m,
Class<K> keyType,
Class<V> valueType)
m - the sorted mapkeyType - the type of the keys permitted to insertvalueType - the type of the values permitted to insert
public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s,
Class<E> type)
s - the sorted settype - the type of the elements permitted to insert
public static <T> boolean addAll(Collection<? super T> c,
T... a)
c - the collection the elements are to be inserted intoa - the elements to insert
UnsupportedOperationException - when the method is not supported
NullPointerException - when c or elements is null, or elements contains one or more
null elements and c doesn't support null elements
public static boolean disjoint(Collection<?> c1,
Collection<?> c2)
c1 - the first collectionc2 - the second collection
NullPointerException - if one of the collections is null
static <E> E checkType(E obj,
Class<E> type)
obj - -
object is to be checkedtype - -
class of object that should be
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||