public class Collections extends Object
Collections contains static methods which operate on
Collection classes.| Modifier and Type | Field and Description |
|---|---|
static List |
EMPTY_LIST
An empty immutable instance of
List. |
static Map |
EMPTY_MAP
An empty immutable instance of
Map. |
static Set |
EMPTY_SET
An empty immutable instance of
Set. |
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
addAll(Collection<? super T> c,
T... a)
Adds all the specified elements to the specified collection.
|
static <T> Queue<T> |
asLifoQueue(Deque<T> deque)
Returns a last-in, first-out queue as a view of
deque. |
static <T> int |
binarySearch(List<? extends Comparable<? super T>> list,
T object)
Performs a binary search for the specified element in the specified
sorted list.
|
static <T> 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.
|
static <E> Collection<E> |
checkedCollection(Collection<E> c,
Class<E> type)
Returns a dynamically typesafe view of the specified collection.
|
static <E> List<E> |
checkedList(List<E> list,
Class<E> type)
Returns a dynamically typesafe view of the specified list.
|
static <K,V> Map<K,V> |
checkedMap(Map<K,V> m,
Class<K> keyType,
Class<V> valueType)
Returns a dynamically typesafe view of the specified map.
|
static <K,V> NavigableMap<K,V> |
checkedNavigableMap(NavigableMap<K,V> m,
Class<K> keyType,
Class<V> valueType)
Returns a dynamically typesafe view of the specified navigable map.
|
static <E> NavigableSet<E> |
checkedNavigableSet(NavigableSet<E> s,
Class<E> type)
Returns a dynamically typesafe view of the specified navigable set.
|
static <E> Queue<E> |
checkedQueue(Queue<E> queue,
Class<E> type)
Returns a dynamically typesafe view of the specified queue.
|
static <E> Set<E> |
checkedSet(Set<E> s,
Class<E> type)
Returns a dynamically typesafe view of the specified set.
|
static <K,V> SortedMap<K,V> |
checkedSortedMap(SortedMap<K,V> m,
Class<K> keyType,
Class<V> valueType)
Returns a dynamically typesafe view of the specified sorted map.
|
static <E> SortedSet<E> |
checkedSortedSet(SortedSet<E> s,
Class<E> type)
Returns a dynamically typesafe view of the specified sorted set.
|
static <T> void |
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 whether the specified collections have no elements in common.
|
static <T> Enumeration<T> |
emptyEnumeration()
Returns an enumeration containing no elements.
|
static <T> Iterator<T> |
emptyIterator()
Returns an iterator containing no elements.
|
static <T> List<T> |
emptyList()
Returns a type-safe empty, immutable
List. |
static <T> ListIterator<T> |
emptyListIterator()
Returns a list iterator containing no elements.
|
static <K,V> Map<K,V> |
emptyMap()
Returns a type-safe empty, immutable
Map. |
static <K,V> NavigableMap<K,V> |
emptyNavigableMap()
Returns an empty navigable map (immutable).
|
static <E> NavigableSet<E> |
emptyNavigableSet()
Returns an empty navigable set (immutable).
|
static <T> Set<T> |
emptySet()
Returns a type-safe empty, immutable
Set. |
static <K,V> SortedMap<K,V> |
emptySortedMap()
Returns an empty sorted map (immutable).
|
static <E> SortedSet<E> |
emptySortedSet()
Returns an empty sorted set (immutable).
|
static <T> Enumeration<T> |
enumeration(Collection<T> collection)
Returns an
Enumeration on the specified collection. |
static <T> void |
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 <T> ArrayList<T> |
list(Enumeration<T> enumeration)
Returns an
ArrayList with all the elements in the enumeration. |
static <T extends Object & Comparable<? super T>> |
max(Collection<? extends T> collection)
Searches the specified collection for the maximum element.
|
static <T> T |
max(Collection<? extends T> collection,
Comparator<? super T> comparator)
Searches the specified collection for the maximum element using the
specified comparator.
|
static <T extends Object & Comparable<? super T>> |
min(Collection<? extends T> collection)
Searches the specified collection for the minimum element.
|
static <T> T |
min(Collection<? extends T> collection,
Comparator<? super T> comparator)
Searches the specified collection for the minimum element using the
specified comparator.
|
static <T> List<T> |
nCopies(int length,
T object)
Returns a list containing the specified number of the specified element.
|
static <E> Set<E> |
newSetFromMap(Map<E,Boolean> map)
Returns a set backed by
map. |
static <T> boolean |
replaceAll(List<T> list,
T obj,
T obj2)
Replaces all occurrences of Object
obj in list with
newObj. |
static void |
reverse(List<?> list)
Modifies the specified
List by reversing the order of the
elements. |
static <T> Comparator<T> |
reverseOrder()
A comparator which reverses the natural order of the elements.
|
static <T> Comparator<T> |
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 by the distance dist |
static int |
roundUpToPowerOfTwo(int i)
Returns the smallest power of two >= its argument, with several caveats:
If the argument is negative but not Integer.MIN_VALUE, the method returns
zero.
|
static int |
secondaryHash(Object key)
Computes a hash code and applies a supplemental hash function to defend
against poor quality hash functions.
|
static int |
secondaryIdentityHash(Object key)
Computes an identity hash code and applies a supplemental hash function to defend
against poor quality hash functions.
|
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 <E> Set<E> |
singleton(E object)
Returns a set containing the specified element.
|
static <E> List<E> |
singletonList(E object)
Returns a list containing the specified element.
|
static <K,V> Map<K,V> |
singletonMap(K key,
V value)
Returns a Map containing the specified key and value.
|
static <T extends Comparable<? super T>> |
sort(List<T> list)
Sorts the given list in ascending natural order.
|
static <T> void |
sort(List<T> list,
Comparator<? super T> comparator)
Sorts the given list using the given comparator.
|
static void |
swap(List<?> list,
int index1,
int index2)
Swaps the elements of list
list at indices index1 and
index2. |
static <T> Collection<T> |
synchronizedCollection(Collection<T> collection)
Returns a wrapper on the specified collection which synchronizes all
access to the collection.
|
static <T> List<T> |
synchronizedList(List<T> list)
Returns a wrapper on the specified List which synchronizes all access to
the List.
|
static <K,V> Map<K,V> |
synchronizedMap(Map<K,V> map)
Returns a wrapper on the specified map which synchronizes all access to
the map.
|
static <K,V> NavigableMap<K,V> |
synchronizedNavigableMap(NavigableMap<K,V> m)
Returns a synchronized (thread-safe) navigable map backed by the
specified navigable map.
|
static <T> NavigableSet<T> |
synchronizedNavigableSet(NavigableSet<T> s)
Returns a synchronized (thread-safe) navigable set backed by the
specified navigable set.
|
static <E> Set<E> |
synchronizedSet(Set<E> set)
Returns a wrapper on the specified set which synchronizes all access to
the set.
|
static <K,V> SortedMap<K,V> |
synchronizedSortedMap(SortedMap<K,V> map)
Returns a wrapper on the specified sorted map which synchronizes all
access to the sorted map.
|
static <E> SortedSet<E> |
synchronizedSortedSet(SortedSet<E> set)
Returns a wrapper on the specified sorted set which synchronizes all
access to the sorted set.
|
static <E> Collection<E> |
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 <E> List<E> |
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 <K,V> Map<K,V> |
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 <K,V> NavigableMap<K,V> |
unmodifiableNavigableMap(NavigableMap<K,? extends V> m)
Returns an unmodifiable view of the
specified navigable map.
|
static <T> NavigableSet<T> |
unmodifiableNavigableSet(NavigableSet<T> s)
Returns an unmodifiable view of the
specified navigable set.
|
static <E> Set<E> |
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 <K,V> SortedMap<K,V> |
unmodifiableSortedMap(SortedMap<K,? extends V> map)
Returns a wrapper on the specified sorted map which throws an
UnsupportedOperationException whenever an attempt is made to
modify the sorted map. |
static <E> SortedSet<E> |
unmodifiableSortedSet(SortedSet<E> set)
Returns a wrapper on the specified sorted set which throws an
UnsupportedOperationException whenever an attempt is made to
modify the sorted set. |
public static <T> int binarySearch(List<? extends Comparable<? super T>> list, T object)
list - the sorted list to search.object - the element to find.-index - 1 where the element would be insertedClassCastException - if 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 search.object - the element to find.comparator - the comparator. If the comparator is null then the
search uses the objects' natural ordering.-index - 1 where the element would be inserted.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)
index >= source.size() will be unchanged.destination - the list whose elements are set from the source list.source - the list with the elements to be copied into the destination.IndexOutOfBoundsException - when the destination list is smaller than the source list.UnsupportedOperationException - when replacing an element in the destination list is not
supported.public static <T> Enumeration<T> enumeration(Collection<T> collection)
Enumeration on the specified collection.collection - the collection to enumerate.public static <T> void fill(List<? super T> list, T object)
list - the list to fill.object - the element to fill the list with.UnsupportedOperationException - when replacing an element in the List is not supported.public 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 search.comparator - the comparator.ClassCastException - when elements in the collection cannot be compared to each
other using the Comparator.public 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 search.comparator - 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 list.object - the element to be added length times to a list.length copies of the element.IllegalArgumentException - when length < 0.public static void reverse(List<?> list)
List by reversing the order of the
elements.list - the list to reverse.UnsupportedOperationException - when replacing an element in the List is not supported.public static <T> Comparator<T> reverseOrder()
Comparator that's returned is Serializable.Comparator instance.public static <T> Comparator<T> reverseOrder(Comparator<T> c)
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.public 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 shuffle.random - the random number generator.UnsupportedOperationException - when replacing an element in the list is not supported.public 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 key.value - the value.public static <T extends Comparable<? super T>> void sort(List<T> list)
ClassCastException - if any element does not implement Comparable,
or if compareTo throws for any pair of elements.public static <T> void sort(List<T> list, Comparator<? super T> comparator)
ClassCastException - if any element does not implement Comparable,
or if compareTo throws for any pair of elements.public static void swap(List<?> list, int index1, int index2)
list at indices index1 and
index2.list - the list to manipulate.index1 - position of the first element to swap with the element in
index2.index2 - 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 are replaced with newObj.list - the list to modify.obj - 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 - the list whose elements are to be rotated.dist - is the distance the list is rotated. This can be any valid
integer. Negative values rotate the list backwards.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 in.sublist - 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 in.sublist - the list to search in list.sublist in
list, or -1.public static <T> ArrayList<T> list(Enumeration<T> enumeration)
ArrayList with all the elements in the enumeration. The elements in the returned ArrayList are in the
same order as in the enumeration.enumeration - the source Enumeration.ArrayList from enumeration.public static <T> Collection<T> synchronizedCollection(Collection<T> collection)
collection - the Collection to wrap in a synchronized collection.public static <T> List<T> synchronizedList(List<T> list)
list - the List to wrap in a synchronized list.public static <K,V> Map<K,V> synchronizedMap(Map<K,V> map)
map - the map to wrap in a synchronized map.public static <E> Set<E> synchronizedSet(Set<E> set)
set - the set to wrap in a synchronized set.public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> map)
map - the sorted map to wrap in a synchronized sorted map.public static <K,V> NavigableMap<K,V> synchronizedNavigableMap(NavigableMap<K,V> m)
It is imperative that the user manually synchronize on the returned
navigable map when traversing any of its collection views, or the
collections views of any of its subMap, headMap or
tailMap views, via Iterator, Spliterator or
Stream:
NavigableMap m = Collections.synchronizedNavigableMap(new TreeMap());
...
Set s = m.keySet(); // Needn't be in synchronized block
...
synchronized (m) { // Synchronizing on m, not s!
Iterator i = s.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
or:
NavigableMap m = Collections.synchronizedNavigableMap(new TreeMap());
NavigableMap m2 = m.subMap(foo, true, bar, false);
...
Set s2 = m2.keySet(); // Needn't be in synchronized block
...
synchronized (m) { // Synchronizing on m, not m2 or s2!
Iterator i = s.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
Failure to follow this advice may result in non-deterministic behavior.
The returned navigable map will be serializable if the specified navigable map is serializable.
K - the class of the map keysV - the class of the map valuesm - the navigable map to be "wrapped" in a synchronized navigable
mappublic static <E> SortedSet<E> synchronizedSortedSet(SortedSet<E> set)
set - the sorted set to wrap in a synchronized sorted set.public static <T> NavigableSet<T> synchronizedNavigableSet(NavigableSet<T> s)
It is imperative that the user manually synchronize on the returned
navigable set when traversing it, or any of its subSet,
headSet, or tailSet views, via Iterator,
Spliterator or Stream:
NavigableSet s = Collections.synchronizedNavigableSet(new TreeSet());
...
synchronized (s) {
Iterator i = s.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
or:
NavigableSet s = Collections.synchronizedNavigableSet(new TreeSet());
NavigableSet s2 = s.headSet(foo, true);
...
synchronized (s) { // Note: s, not s2!!!
Iterator i = s2.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
Failure to follow this advice may result in non-deterministic behavior.
The returned navigable set will be serializable if the specified navigable set is serializable.
T - the class of the objects in the sets - the navigable set to be "wrapped" in a synchronized navigable
setpublic static <E> Collection<E> unmodifiableCollection(Collection<? extends E> collection)
UnsupportedOperationException whenever an attempt is made to
modify the collection.collection - the collection to wrap in an unmodifiable collection.public static <E> List<E> unmodifiableList(List<? extends E> list)
UnsupportedOperationException whenever an attempt is made to
modify the list.list - the list to wrap in an unmodifiable 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 to wrap in an unmodifiable map.public static <E> Set<E> unmodifiableSet(Set<? extends E> set)
UnsupportedOperationException whenever an attempt is made to
modify the set.set - the set to wrap in an unmodifiable set.public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K,? extends V> map)
UnsupportedOperationException whenever an attempt is made to
modify the sorted map.map - the sorted map to wrap in an unmodifiable sorted map.public static <E> SortedSet<E> unmodifiableSortedSet(SortedSet<E> set)
UnsupportedOperationException whenever an attempt is made to
modify the sorted set.set - the sorted set to wrap in an unmodifiable sorted set.public static <K,V> NavigableMap<K,V> unmodifiableNavigableMap(NavigableMap<K,? extends V> m)
subMap, headMap, or tailMap views, result in
an UnsupportedOperationException.The returned navigable map will be serializable if the specified navigable map is serializable.
K - the class of the map keysV - the class of the map valuesm - the navigable map for which an unmodifiable view is to be
returnedpublic static <T> NavigableSet<T> unmodifiableNavigableSet(NavigableSet<T> s)
subSet, headSet, or tailSet views, result in
an UnsupportedOperationException.The returned navigable set will be serializable if the specified navigable set is serializable.
T - the class of the objects in the sets - the navigable set for which an unmodifiable view is to be
returnedpublic static int frequency(Collection<?> c, Object o)
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 <E> SortedSet<E> emptySortedSet()
This example illustrates the type-safe way to obtain an empty sorted set:
SortedSet<String> s = Collections.emptySortedSet();
E - type of elements, if there were any, in the setpublic static <E> NavigableSet<E> emptyNavigableSet()
This example illustrates the type-safe way to obtain an empty navigable set:
NavigableSet<String> s = Collections.emptyNavigableSet();
E - type of elements, if there were any, in the setpublic static final <K,V> SortedMap<K,V> emptySortedMap()
This example illustrates the type-safe way to obtain an empty map:
SortedMap<String, Date> s = Collections.emptySortedMap();
K - the class of the map keysV - the class of the map valuespublic static final <K,V> NavigableMap<K,V> emptyNavigableMap()
This example illustrates the type-safe way to obtain an empty map:
NavigableMap<String, Date> s = Collections.emptyNavigableMap();
K - the class of the map keysV - the class of the map valuespublic static <T> Enumeration<T> emptyEnumeration()
public static <T> Iterator<T> emptyIterator()
public static <T> ListIterator<T> emptyListIterator()
public static <E> Collection<E> checkedCollection(Collection<E> c, Class<E> type)
ClassCastException. At creation time the types in c are
not checked for correct type.c - the collection to be wrapped in a typesafe collection.type - the type of the elements permitted to insert.public static <E> Queue<E> checkedQueue(Queue<E> queue, Class<E> type)
ClassCastException. Assuming a queue contains
no incorrectly typed elements prior to the time a dynamically typesafe
view is generated, and that all subsequent access to the queue
takes place through the view, it is guaranteed that the
queue cannot contain an incorrectly typed element.
A discussion of the use of dynamically typesafe views may be
found in the documentation for the checkedCollection method.
The returned queue will be serializable if the specified queue is serializable.
Since null is considered to be a value of any reference
type, the returned queue permits insertion of null elements
whenever the backing queue does.
E - the class of the objects in the queuequeue - the queue for which a dynamically typesafe view is to be
returnedtype - the type of element that queue is permitted to holdpublic static <K,V> Map<K,V> checkedMap(Map<K,V> m, Class<K> keyType, Class<V> valueType)
ClassCastException. At creation time the types in m are
not checked for correct type.m - the map to be wrapped in a typesafe map.keyType - the type of the keys permitted to insert.valueType - the type of the values permitted to insert.public static <E> List<E> checkedList(List<E> list, Class<E> type)
ClassCastException. At creation time the types in list
are not checked for correct type.list - the list to be wrapped in a typesafe list.type - the type of the elements permitted to insert.public static <E> Set<E> checkedSet(Set<E> s, Class<E> type)
ClassCastException. At creation time the types in s are
not checked for correct type.s - the set to be wrapped in a typesafe set.type - 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)
ClassCastException. At creation time the types in m are
not checked for correct type.m - the sorted map to be wrapped in a typesafe sorted map.keyType - the type of the keys permitted to insert.valueType - the type of the values permitted to insert.public static <K,V> NavigableMap<K,V> checkedNavigableMap(NavigableMap<K,V> m, Class<K> keyType, Class<V> valueType)
ClassCastException.
Similarly, any attempt to modify the value currently associated with
a key will result in an immediate ClassCastException,
whether the modification is attempted directly through the map
itself, or through a Map.Entry instance obtained from the
map's entry set view.
Assuming a map contains no incorrectly typed keys or values prior to the time a dynamically typesafe view is generated, and that all subsequent access to the map takes place through the view (or one of its collection views), it is guaranteed that the map cannot contain an incorrectly typed key or value.
A discussion of the use of dynamically typesafe views may be
found in the documentation for the checkedCollection method.
The returned map will be serializable if the specified map is serializable.
Since null is considered to be a value of any reference
type, the returned map permits insertion of null keys or values
whenever the backing map does.
K - type of map keysV - type of map valuesm - the map for which a dynamically typesafe view is to be
returnedkeyType - the type of key that m is permitted to holdvalueType - the type of value that m is permitted to holdpublic static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s, Class<E> type)
ClassCastException. At creation time the types in s are
not checked for correct type.s - the sorted set to be wrapped in a typesafe sorted set.type - the type of the elements permitted to insert.public static <E> NavigableSet<E> checkedNavigableSet(NavigableSet<E> s, Class<E> type)
ClassCastException. Assuming a navigable set
contains no incorrectly typed elements prior to the time a
dynamically typesafe view is generated, and that all subsequent
access to the navigable set takes place through the view, it is
guaranteed that the navigable set cannot contain an incorrectly
typed element.
A discussion of the use of dynamically typesafe views may be
found in the documentation for the checkedCollection method.
The returned navigable set will be serializable if the specified navigable set is serializable.
Since null is considered to be a value of any reference
type, the returned navigable set permits insertion of null elements
whenever the backing sorted set does.
E - the class of the objects in the sets - the navigable set for which a dynamically typesafe view is to be
returnedtype - the type of element that s is permitted to hold@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... a)
c - the collection the elements are to be inserted into.a - the elements to insert.UnsupportedOperationException - when the method is not supported.NullPointerException - when c or a is null, or a
contains one or more null elements and c
doesn't support null elements.IllegalArgumentException - if at least one of the elements can't be inserted into the
collection.public static boolean disjoint(Collection<?> c1, Collection<?> c2)
c1 - the first collection.c2 - the second collection.true if the collections have no elements in common,
false otherwise.NullPointerException - if one of the collections is null.public static <E> Set<E> newSetFromMap(Map<E,Boolean> map)
map.IllegalArgumentException - if the map is not emptypublic static <T> Queue<T> asLifoQueue(Deque<T> deque)
deque.public static int secondaryHash(Object key)
public static int secondaryIdentityHash(Object key)
public static int roundUpToPowerOfTwo(int i)