|
Final | |||||||
| 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.
| Field Summary | |
|---|---|
static List |
EMPTY_LIST
The unmutable, serializable empty list. |
static Map |
EMPTY_MAP
The unmutable, serializable empty map. |
static Set |
EMPTY_SET
The unmutable, serializable empty set. |
| Method Summary | ||
|---|---|---|
static
|
binarySearch(List<? extends Comparable<? super T>> list,
T object)
Performs a binary search for the specified element in the specified sorted List. |
|
static int |
binarySearch(List list,
Object object,
Comparator comparator)
Performs a binary search for the specified element in the specified sorted List using the specified Comparator. |
|
static void |
copy(List destination,
List source)
Copies the elements from the source list to the destination list. |
|
static
|
emptyList()
Returns an unmutable, serializable empty list. |
|
static
|
emptyMap()
Returns an unmutable, serializable empty map. |
|
static
|
emptySet()
Returns an unmutable, serializable empty set. |
|
static Enumeration |
enumeration(Collection collection)
Answers an Enumeration on the specified Collection. |
|
static void |
fill(List list,
Object object)
Fills the specified List with the specified element. |
|
static int |
indexOfSubList(List list,
List sublist)
Searches the list for sublist
and answers the beginning index of the first occurance. |
|
static int |
lastIndexOfSubList(List list,
List sublist)
Searches the list for sublist
and answers the beginning index of the last occurance. |
|
static ArrayList |
list(Enumeration enumeration)
Answers an ArrayList with all the elements in the enumeration. |
|
static Object |
max(Collection collection)
Searches the specified Collection for the maximum element. |
|
static Object |
max(Collection collection,
Comparator comparator)
Searches the specified Collection for the maximum element using the specified Comparator. |
|
static Object |
min(Collection collection)
Searches the specified Collection for the minimum element. |
|
static Object |
min(Collection collection,
Comparator comparator)
Searches the specified Collection for the minimum element using the specified Comparator. |
|
static List |
nCopies(int length,
Object object)
Answers a List containing the specified number of the specified element. |
|
static boolean |
replaceAll(List list,
Object obj,
Object obj2)
Replaces all occurances of Object obj
in list with newObj. |
|
static void |
reverse(List list)
Reverses the order of the elements in the specified List. |
|
static Comparator |
reverseOrder()
A Comparator which reverses the natural order of the elements. |
|
static void |
rotate(List list,
int dist)
Rotates the elements in List list by the distancedist |
|
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 Set |
singleton(Object object)
Answers a Set containing the specified element. |
|
static List |
singletonList(Object object)
Answers a List containing the specified element. |
|
static Map |
singletonMap(Object key,
Object value)
Answers a Map containing the specified key and value. |
|
static void |
sort(List list)
Sorts the specified List in ascending order. |
|
static void |
sort(List list,
Comparator 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)
Answers a wrapper on the specified Collection which synchronizes all access to the Collection. |
|
static
|
synchronizedList(List<T> list)
Answers a wrapper on the specified List which synchronizes all access to the List. |
|
static
|
synchronizedMap(Map<K,V> map)
Answers a wrapper on the specified Map which synchronizes all access to the Map. |
|
static
|
synchronizedSet(Set<T> set)
Answers a wrapper on the specified Set which synchronizes all access to the Set. |
|
static
|
synchronizedSortedMap(SortedMap<K,V> map)
Answers a wrapper on the specified SortedMap which synchronizes all access to the SortedMap. |
|
static
|
synchronizedSortedSet(SortedSet<T> set)
Answers a wrapper on the specified SortedSet which synchronizes all access to the SortedSet. |
|
static
|
unmodifiableCollection(Collection<? extends T> collection)
Answers a wrapper on the specified Collection which throws an UnsupportedOperationException whenever an attempt
is made to modify the Collection. |
|
static
|
unmodifiableList(List<? extends T> list)
Answers 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)
Answers a wrapper on the specified Map which throws an UnsupportedOperationException whenever an attempt
is made to modify the Map. |
|
static
|
unmodifiableSet(Set<? extends T> set)
Answers 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)
Answers a wrapper on the specified SortedMap which throws an UnsupportedOperationException whenever an attempt
is made to modify the SortedMap. |
|
static
|
unmodifiableSortedSet(SortedSet<T> set)
Answers 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
emptyList()public static final Set EMPTY_SET
emptySet()public static final Map EMPTY_MAP
emptyMap()| Method Detail |
|---|
@SuppressWarnings(value="unchecked") public static final <T> List<T> emptyList()
EMPTY_LIST this method
provides type safety.
T - the types theoretically contained in this list
@SuppressWarnings(value="unchecked") public static final <K,V> Map<K,V> emptyMap()
EMPTY_MAP this method
provides type safety.
K - the key types theoretically contained in this mapV - the value types theoretically contained in this map
@SuppressWarnings(value="unchecked") public static final <T> Set<T> emptySet()
EMPTY_SET this method
provides type safety.
T - the types theoretically contained in this set
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 seach
element does not implement Comparable, or cannot be compared
to each otherpublic static int binarySearch(List list,
Object object,
Comparator comparator)
list - the sorted List to searchobject - the element to findcomparator - the Comparator or null if
Comparable.compareTo(Object) should be used
ClassCastException - when an element in the list and the searched
element cannot be compared to each other using the Comparatorpublic static void copy(List destination,
List source)
destination - the copy-to listsource - the copy-from list
IndexOutOfBoundsException - when the destination List is smaller than
the source List
UnsupportedOperationException - when replacing an element in the destination
list is not supportedpublic static Enumeration enumeration(Collection collection)
collection - the Collection to enumerate
public static void fill(List list,
Object object)
list - the List to fillobject - the fill element
UnsupportedOperationException - when replacing an element in the
List is not supportedpublic static Object max(Collection collection)
collection - the Collection to search
ClassCastException - when an element in the Collection does not
implement Comparable or elements cannot be compared to each otherpublic static Object max(Collection collection,
Comparator comparator)
collection - the Collection to searchcomparator - the Comparator
ClassCastException - when elements in the Collection cannot be compared
to each other using the Comparatorpublic static Object min(Collection collection)
collection - the Collection to search
ClassCastException - when an element in the Collection does not
implement Comparable or elements cannot be compared to each otherpublic static Object min(Collection collection,
Comparator comparator)
collection - the Collection to searchcomparator - the Comparator
ClassCastException - when elements in the Collection cannot be compared
to each other using the Comparatorpublic static List nCopies(int length,
Object 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 - the List to reverse
UnsupportedOperationException - when replacing an element in the
List is not supportedpublic static Comparator reverseOrder()
public static void shuffle(List list)
list - the List to shuffle
UnsupportedOperationException - when replacing an element in the
List is not supportedpublic 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 Set singleton(Object object)
object - the element
public static List singletonList(Object object)
object - the element
public static Map singletonMap(Object key,
Object value)
key - the keyvalue - the value
public static void sort(List 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 otherpublic static void sort(List list,
Comparator comparator)
list - the List to be sortedcomparator - the Comparator
ClassCastException - when elements in the List cannot be compared
to each other using the Comparatorpublic 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 listpublic static boolean replaceAll(List list,
Object obj,
Object obj2)
obj
in list with newObj.
If the obj is null,
then all occurances of null is replaced with newObj.
list - the List to modifyobj - the Object to find and replace occurances of.obj2 - the Object to replace all occurances of obj in list
obj has been found in list
UnsupportedOperationException - if the list does not support setting elementspublic static void rotate(List list,
int dist)
list by the distancedist
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]
list - dist - It can be any integer: 0, positive, negative, larger than the list sizepublic static int indexOfSubList(List list,
List sublist)
list for sublist
and answers the beginning index of the first occurance.
-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 int lastIndexOfSubList(List list,
List sublist)
list for sublist
and answers the beginning index of the last occurance.
-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 ArrayList list(Enumeration 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
NullPointerException - if collection is nullpublic static <T> List<T> synchronizedList(List<T> list)
list - the List
NullPointerException - if list is nullpublic static <K,V> Map<K,V> synchronizedMap(Map<K,V> map)
map - the Map
NullPointerException - if map is nullpublic static <T> Set<T> synchronizedSet(Set<T> set)
set - the Set
NullPointerException - if set is nullpublic static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> map)
map - the SortedMap
NullPointerException - if map is nullpublic static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> set)
set - the SortedSet
NullPointerException - if set is nullpublic static <T> Collection<T> unmodifiableCollection(Collection<? extends T> collection)
UnsupportedOperationException whenever an attempt
is made to modify the Collection.
collection - the Collection
NullPointerException - if collection is nullpublic static <T> List<T> unmodifiableList(List<? extends T> list)
UnsupportedOperationException whenever an attempt
is made to modify the List.
list - the List
NullPointerException - if list is nullpublic 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
NullPointerException - if map is nullpublic static <T> Set<T> unmodifiableSet(Set<? extends T> set)
UnsupportedOperationException whenever an attempt
is made to modify the Set.
set - the Set
NullPointerException - if set is nullpublic 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
NullPointerException - if map is nullpublic static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> set)
UnsupportedOperationException whenever an attempt
is made to modify the SortedSet.
set - the SortedSet
NullPointerException - if set is null
|
Final | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||