java.lang.Object | |
↳ | java.util.Collections |
Collections
contains static methods which operate on
Collection
classes.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
List | EMPTY_LIST | An empty immutable instance of List . |
|||||||||
Map | EMPTY_MAP | An empty immutable instance of Map . |
|||||||||
Set | EMPTY_SET | An empty immutable instance of Set . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds all the specified elements to the specified collection.
| |||||||||||
Returns a last-in, first-out queue as a view of
deque . | |||||||||||
Performs a binary search for the specified element in the specified
sorted list.
| |||||||||||
Performs a binary search for the specified element in the specified
sorted list using the specified comparator.
| |||||||||||
Returns a dynamically typesafe view of the specified collection.
| |||||||||||
Returns a dynamically typesafe view of the specified list.
| |||||||||||
Returns a dynamically typesafe view of the specified map.
| |||||||||||
Returns a dynamically typesafe view of the specified set.
| |||||||||||
Returns a dynamically typesafe view of the specified sorted map.
| |||||||||||
Returns a dynamically typesafe view of the specified sorted set.
| |||||||||||
Copies the elements from the source list to the destination list.
| |||||||||||
Returns whether the specified collections have no elements in common.
| |||||||||||
Returns a type-safe empty, immutable
List . | |||||||||||
Returns a type-safe empty, immutable
Map . | |||||||||||
Returns a type-safe empty, immutable
Set . | |||||||||||
Returns an
Enumeration on the specified collection. | |||||||||||
Fills the specified list with the specified element.
| |||||||||||
Returns the number of elements in the
Collection that match the
Object passed. | |||||||||||
Searches the
list for sublist and returns the beginning
index of the first occurrence. | |||||||||||
Searches the
list for sublist and returns the beginning
index of the last occurrence. | |||||||||||
Returns an
ArrayList with all the elements in the enumeration . | |||||||||||
Searches the specified collection for the maximum element.
| |||||||||||
Searches the specified collection for the maximum element using the
specified comparator.
| |||||||||||
Searches the specified collection for the minimum element using the
specified comparator.
| |||||||||||
Searches the specified collection for the minimum element.
| |||||||||||
Returns a list containing the specified number of the specified element.
| |||||||||||
Returns a set backed by
map . | |||||||||||
Replaces all occurrences of Object
obj in list with
newObj . | |||||||||||
Modifies the specified
List by reversing the order of the
elements. | |||||||||||
A comparator which reverses the natural order of the elements.
| |||||||||||
Returns a
Comparator that reverses the order of the
Comparator passed. | |||||||||||
Rotates the elements in
list by the distance dist
e.g. | |||||||||||
Moves every element of the list to a random new position in the list
using the specified random number generator.
| |||||||||||
Moves every element of the list to a random new position in the list.
| |||||||||||
Returns a set containing the specified element.
| |||||||||||
Returns a list containing the specified element.
| |||||||||||
Returns a Map containing the specified key and value.
| |||||||||||
Sorts the specified list using the specified comparator.
| |||||||||||
Sorts the specified list in ascending natural order.
| |||||||||||
Swaps the elements of list
list at indices index1 and
index2 . | |||||||||||
Returns a wrapper on the specified collection which synchronizes all
access to the collection.
| |||||||||||
Returns a wrapper on the specified List which synchronizes all access to
the List.
| |||||||||||
Returns a wrapper on the specified map which synchronizes all access to
the map.
| |||||||||||
Returns a wrapper on the specified set which synchronizes all access to
the set.
| |||||||||||
Returns a wrapper on the specified sorted map which synchronizes all
access to the sorted map.
| |||||||||||
Returns a wrapper on the specified sorted set which synchronizes all
access to the sorted set.
| |||||||||||
Returns a wrapper on the specified collection which throws an
UnsupportedOperationException whenever an attempt is made to
modify the collection. | |||||||||||
Returns a wrapper on the specified list which throws an
UnsupportedOperationException whenever an attempt is made to
modify the list. | |||||||||||
Returns a wrapper on the specified map which throws an
UnsupportedOperationException whenever an attempt is made to
modify the map. | |||||||||||
Returns a wrapper on the specified set which throws an
UnsupportedOperationException whenever an attempt is made to
modify the set. | |||||||||||
Returns a wrapper on the specified sorted map which throws an
UnsupportedOperationException whenever an attempt is made to
modify the sorted map. | |||||||||||
Returns a wrapper on the specified sorted set which throws an
UnsupportedOperationException whenever an attempt is made to
modify the sorted set. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Adds all the specified elements to the specified collection.
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. |
Returns a last-in, first-out queue as a view of deque
.
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.
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. |
---|
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.
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. |
---|
Returns a dynamically typesafe view of the specified collection. Trying
to insert an element of the wrong type into this collection throws a
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. |
Returns a dynamically typesafe view of the specified list. Trying to
insert an element of the wrong type into this list throws a
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. |
Returns a dynamically typesafe view of the specified map. Trying to
insert an element of the wrong type into this map throws a
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. |
Returns a dynamically typesafe view of the specified set. Trying to
insert an element of the wrong type into this set throws a
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. |
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
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. |
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
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. |
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 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. |
Returns whether the specified collections have no elements in common.
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 .
|
---|
Returns an Enumeration
on the specified collection.
collection | the collection to enumerate. |
---|
Fills the specified list with the specified element.
list | the list to fill. |
---|---|
object | the element to fill the list with. |
UnsupportedOperationException | when replacing an element in the List is not supported. |
---|
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 . |
---|
Searches the 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.
Searches the 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.
Returns an 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
.
Searches the specified collection for the maximum element.
collection | the collection to search. |
---|
ClassCastException | when an element in the collection does not implement
Comparable or elements cannot be compared to each
other.
|
---|
Searches the specified collection for the maximum element using the specified comparator.
collection | the collection to search. |
---|---|
comparator | the comparator. |
ClassCastException | when elements in the collection cannot be compared to each
other using the Comparator .
|
---|
Searches the specified collection for the minimum element using the specified comparator.
collection | the collection to search. |
---|---|
comparator | the comparator. |
ClassCastException | when elements in the collection cannot be compared to each
other using the Comparator .
|
---|
Searches the specified collection for the minimum element.
collection | the collection to search. |
---|
ClassCastException | when an element in the collection does not implement
Comparable or elements cannot be compared to each
other.
|
---|
Returns a list containing the specified number of the specified element. The list cannot be modified. The list is serializable.
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 .
|
---|
Returns a set backed by map
.
IllegalArgumentException | if the map is not empty |
---|
Replaces all occurrences of Object 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. |
---|
Modifies the specified List
by reversing the order of the
elements.
list | the list to reverse. |
---|
UnsupportedOperationException | when replacing an element in the List is not supported. |
---|
A comparator which reverses the natural order of the elements. The
Comparator
that's returned is Serializable
.
Comparator
instance.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.Rotates the elements in 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. |
Moves every element of the list to a random new position in the list using the specified random number generator.
list | the list to shuffle. |
---|---|
random | the random number generator. |
UnsupportedOperationException | when replacing an element in the list is not supported. |
---|
Moves every element of the list to a random new position in the list.
list | the List to shuffle. |
---|
UnsupportedOperationException | when replacing an element in the List is not supported. |
---|
Returns a set containing the specified element. The set cannot be modified. The set is serializable.
object | the element. |
---|
Returns a list containing the specified element. The list cannot be modified. The list is serializable.
object | the element. |
---|
Returns a Map containing the specified key and value. The map cannot be modified. The map is serializable.
key | the key. |
---|---|
value | the value. |
Sorts the specified list using the specified comparator. The algorithm is stable which means equal elements don't get reordered.
list | the list to be sorted. |
---|---|
comparator | the comparator. |
ClassCastException | when elements in the list cannot be compared to each other using the comparator. |
---|
Sorts the specified list in ascending natural order. The algorithm is stable which means equal elements don't get reordered.
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. |
---|
Swaps the elements of list 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. |
---|
Returns a wrapper on the specified collection which synchronizes all access to the collection.
collection | the Collection to wrap in a synchronized collection. |
---|
Returns a wrapper on the specified List which synchronizes all access to the List.
list | the List to wrap in a synchronized list. |
---|
Returns a wrapper on the specified map which synchronizes all access to the map.
map | the map to wrap in a synchronized map. |
---|
Returns a wrapper on the specified set which synchronizes all access to the set.
set | the set to wrap in a synchronized set. |
---|
Returns a wrapper on the specified sorted map which synchronizes all access to the sorted map.
map | the sorted map to wrap in a synchronized sorted map. |
---|
Returns a wrapper on the specified sorted set which synchronizes all access to the sorted set.
set | the sorted set to wrap in a synchronized sorted set. |
---|
Returns a wrapper on the specified collection which throws an
UnsupportedOperationException
whenever an attempt is made to
modify the collection.
collection | the collection to wrap in an unmodifiable collection. |
---|
Returns a wrapper on the specified list which throws an
UnsupportedOperationException
whenever an attempt is made to
modify the list.
list | the list to wrap in an unmodifiable list. |
---|
Returns a wrapper on the specified map which throws an
UnsupportedOperationException
whenever an attempt is made to
modify the map.
map | the map to wrap in an unmodifiable map. |
---|
Returns a wrapper on the specified set which throws an
UnsupportedOperationException
whenever an attempt is made to
modify the set.
set | the set to wrap in an unmodifiable set. |
---|
Returns a wrapper on the specified sorted map which throws an
UnsupportedOperationException
whenever an attempt is made to
modify the sorted map.
map | the sorted map to wrap in an unmodifiable sorted map. |
---|
Returns a wrapper on the specified sorted set which throws an
UnsupportedOperationException
whenever an attempt is made to
modify the sorted set.
set | the sorted set to wrap in an unmodifiable sorted set. |
---|