Collections
constCollections:object
Defined in: src/Collections.ts:1582
Static algorithms and factories that work on any collection: sorting, searching, reordering, empty and singleton collections, and unmodifiable, checked and synchronized wrappers.
List algorithms use get/set loops on lists with the RandomAccess brand and list iterators (or one array
copy) on others, so they stay O(n) on a LinkedList. Every method throws NullPointerException for a
null or undefined collection argument.
Type Declaration
Section titled “Type Declaration”addAll
Section titled “addAll”addAll: <
E>(coll, …elements) =>boolean
Adds each of elements to coll in order; returns true if coll changed.
Adds every element; true if the collection changed.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
elements
Section titled “elements”…E[]
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”UnsupportedOperationException if coll does not support add
asLifoQueue
Section titled “asLifoQueue”asLifoQueue: <
E>(deque) =>Queue<E>
Returns a last-in-first-out Queue view of deque: add/offer push at the front and remove/poll/
element/peek read the front, so the queue behaves as a stack. equals/hashCode are by identity.
Last-in-first-out Queue view of a deque: add/offer push at the front, remove/poll/element/peek read the front, addAll adds each element in turn at the front. equals/hashCode are by identity.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Deque<E>
Returns
Section titled “Returns”Queue<E>
binarySearch
Section titled “binarySearch”binarySearch: <
E>(list,key,c?) =>number
Searches list, which must be sorted ascending by c (natural ordering when c is null or omitted), for key.
O(log n) comparisons; a list without the RandomAccess brand also costs O(n) iterator moves.
The result is undefined if the list is not sorted.
Binary search in a list sorted by c (natural ordering when omitted).
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
E
Comparator<E> | null
Returns
Section titled “Returns”number
the index of a match, else -(insertionPoint) - 1
Returns
Section titled “Returns”the index of a matching element (any one, if there are several), otherwise
-(insertionPoint) - 1, where insertionPoint is the index at which key would be inserted;
so the result is >= 0 only when the key is found
Throws
Section titled “Throws”ClassCastException if natural ordering meets values that cannot be compared
checkedCollection
Section titled “checkedCollection”checkedCollection: <
E>(c,type) =>Collection<E>
Returns a live view of c that throws ClassCastException when an element failing type is inserted
(null passes the check; the backing collection decides). equals/hashCode are by identity. addAll checks
every element before adding any.
View that throws ClassCastException when an element failing type is inserted. equals/hashCode are by identity.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”Collection<E>
type
runtime check standing in for a class token, e.g. (x) => typeof x === 'string'
checkedList
Section titled “checkedList”checkedList: <
E>(l,type) =>List<E>
Returns a live list view that type-checks every inserted element, including through set, replaceAll, list
iterators and subList/reversed() views. List equality.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
Returns
Section titled “Returns”List<E>
Throws
Section titled “Throws”ClassCastException when an element failing type is inserted
checkedMap
Section titled “checkedMap”checkedMap: <
K,V>(m,keyType,valueType) =>Map<K,V>
Returns a live map view that type-checks keys and values on every way in: put, putIfAbsent, replace,
putAll (checked before any is put), results of replaceAll/compute*/merge, and setValue on entries.
Map equality.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”Map<K, V>
keyType
Section titled “keyType”valueType
Section titled “valueType”Returns
Section titled “Returns”Map<K, V>
Throws
Section titled “Throws”ClassCastException when a key fails keyType or a value fails valueType
checkedNavigableMap
Section titled “checkedNavigableMap”checkedNavigableMap: <
K,V>(m,keyType,valueType) =>NavigableMap<K,V>
Like checkedMap, for a navigable map; derived maps and key sets are checked too.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”NavigableMap<K, V>
keyType
Section titled “keyType”valueType
Section titled “valueType”Returns
Section titled “Returns”NavigableMap<K, V>
Throws
Section titled “Throws”ClassCastException when a key fails keyType or a value fails valueType
checkedNavigableSet
Section titled “checkedNavigableSet”checkedNavigableSet: <
E>(s,type) =>NavigableSet<E>
Returns a live navigable-set view that type-checks every inserted element, including through derived views.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”NavigableSet<E>
Returns
Section titled “Returns”NavigableSet<E>
Throws
Section titled “Throws”ClassCastException when an element failing type is inserted
checkedQueue
Section titled “checkedQueue”checkedQueue: <
E>(q,type) =>Queue<E>
Returns a live queue view that type-checks every inserted element (add, offer, …).
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Queue<E>
Returns
Section titled “Returns”Queue<E>
Throws
Section titled “Throws”ClassCastException when an element failing type is inserted
checkedSet
Section titled “checkedSet”checkedSet: <
E>(s,type) =>Set<E>
Returns a live set view that type-checks every inserted element. Set equality.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Set<E>
Returns
Section titled “Returns”Set<E>
Throws
Section titled “Throws”ClassCastException when an element failing type is inserted
checkedSortedMap
Section titled “checkedSortedMap”checkedSortedMap: <
K,V>(m,keyType,valueType) =>SortedMap<K,V>
Like checkedMap, for a sorted map; sub-map views are checked too.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”SortedMap<K, V>
keyType
Section titled “keyType”valueType
Section titled “valueType”Returns
Section titled “Returns”SortedMap<K, V>
Throws
Section titled “Throws”ClassCastException when a key fails keyType or a value fails valueType
checkedSortedSet
Section titled “checkedSortedSet”checkedSortedSet: <
E>(s,type) =>SortedSet<E>
Returns a live sorted-set view that type-checks every inserted element, including through sub-set views.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”SortedSet<E>
Returns
Section titled “Returns”SortedSet<E>
Throws
Section titled “Throws”ClassCastException when an element failing type is inserted
copy: <
E>(dest,src) =>void
Copies src over the first src.size() elements of dest; the rest of dest is unchanged. O(n).
Copies src over the first src.size() elements of dest.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
List<E>
Returns
Section titled “Returns”void
Throws
Section titled “Throws”IndexOutOfBoundsException if dest is shorter
Throws
Section titled “Throws”IndexOutOfBoundsException if dest is shorter than src
Throws
Section titled “Throws”UnsupportedOperationException if dest does not support set
disjoint
Section titled “disjoint”disjoint: (
c1,c2) =>boolean
Returns true if c1 and c2 have no element in common. Iterates one collection and calls contains on the
other, preferring a Set (or else the larger collection) for the contains side.
True when the two collections have no element in common.
Parameters
Section titled “Parameters”Collection<unknown>
Collection<unknown>
Returns
Section titled “Returns”boolean
EMPTY_LIST
Section titled “EMPTY_LIST”EMPTY_LIST:
List<never>
The shared immutable empty list, typed never; emptyList() returns the same instance with an element type.
EMPTY_MAP
Section titled “EMPTY_MAP”EMPTY_MAP:
Map<never,never>
The shared immutable empty map, typed never; emptyMap() returns the same instance with key and value types.
EMPTY_SET
Section titled “EMPTY_SET”EMPTY_SET:
Set<never>
The shared immutable empty set, typed never; emptySet() returns the same instance with an element type.
emptyEnumeration
Section titled “emptyEnumeration”emptyEnumeration: <
E>() =>Enumeration<E>
Returns the shared enumeration over nothing: hasMoreElements() is false, nextElement() throws NoSuchElementException.
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”Enumeration<E>
emptyIterator
Section titled “emptyIterator”emptyIterator: <
E>() =>Iterator<E>
Returns the shared iterator over nothing: hasNext() is false, next() throws NoSuchElementException,
remove() throws IllegalStateException.
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”Iterator<E>
emptyList
Section titled “emptyList”emptyList: <
E>() =>List<E>
Returns the shared immutable empty list (Collections.EMPTY_LIST); random access.
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”List<E>
emptyListIterator
Section titled “emptyListIterator”emptyListIterator: <
E>() =>ListIterator<E>
Returns the shared list iterator over nothing: next()/previous() throw NoSuchElementException,
remove()/set() throw IllegalStateException, add() throws UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”ListIterator<E>
emptyMap
Section titled “emptyMap”emptyMap: <
K,V>() =>Map<K,V>
Returns the shared immutable empty map (Collections.EMPTY_MAP).
Type Parameters
Section titled “Type Parameters”K
V
Returns
Section titled “Returns”Map<K, V>
emptyNavigableMap
Section titled “emptyNavigableMap”emptyNavigableMap: <
K,V>() =>NavigableMap<K,V>
Returns the shared immutable empty navigable map (natural ordering); it rejects null keys like a TreeMap.
Type Parameters
Section titled “Type Parameters”K
V
Returns
Section titled “Returns”NavigableMap<K, V>
emptyNavigableSet
Section titled “emptyNavigableSet”emptyNavigableSet: <
E>() =>NavigableSet<E>
Returns the shared immutable empty navigable set (natural ordering); lower/floor/ceiling/higher return
null. Like a TreeSet, it rejects null queries with NullPointerException.
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”NavigableSet<E>
emptySet
Section titled “emptySet”emptySet: <
E>() =>Set<E>
Returns the shared immutable empty set (Collections.EMPTY_SET).
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”Set<E>
emptySortedMap
Section titled “emptySortedMap”emptySortedMap: <
K,V>() =>SortedMap<K,V>
Returns the shared immutable empty sorted map (natural ordering); it rejects null keys like a TreeMap.
Type Parameters
Section titled “Type Parameters”K
V
Returns
Section titled “Returns”SortedMap<K, V>
emptySortedSet
Section titled “emptySortedSet”emptySortedSet: <
E>() =>SortedSet<E>
Returns the shared immutable empty sorted set (natural ordering). Like a TreeSet, it rejects null queries
with NullPointerException; first()/last() throw NoSuchElementException.
Type Parameters
Section titled “Type Parameters”E
Returns
Section titled “Returns”SortedSet<E>
enumeration
Section titled “enumeration”enumeration: <
E>(c) =>Enumeration<E>
Returns an Enumeration over c’s iterator, for legacy APIs. Its asIterator() does not support remove().
Enumeration over c’s iterator.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”Enumeration<E>
fill: <
E>(list,v) =>void
Replaces every element of list with v. O(n).
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
E
Returns
Section titled “Returns”void
Throws
Section titled “Throws”UnsupportedOperationException if the list does not support set
frequency
Section titled “frequency”frequency: (
coll,o) =>number
Returns the number of elements of coll equal to o (by Objects.equals). O(n).
Number of elements equal (Objects.equals) to o.
Parameters
Section titled “Parameters”Collection<unknown>
unknown
Returns
Section titled “Returns”number
indexOfSubList
Section titled “indexOfSubList”indexOfSubList: (
source,target) =>number
Returns the first index at which target occurs as a contiguous run in source, or -1. An empty target
matches at 0. O(n·m).
First index where target occurs as a contiguous run in source, or -1.
Parameters
Section titled “Parameters”source
Section titled “source”List<unknown>
target
Section titled “target”List<unknown>
Returns
Section titled “Returns”number
lastIndexOfSubList
Section titled “lastIndexOfSubList”lastIndexOfSubList: (
source,target) =>number
Returns the last index at which target occurs as a contiguous run in source, or -1. An empty target
matches at source.size(). O(n·m).
Last index where target occurs as a contiguous run in source, or -1.
Parameters
Section titled “Parameters”source
Section titled “source”List<unknown>
target
Section titled “target”List<unknown>
Returns
Section titled “Returns”number
list: <
E>(e) =>ArrayList<E>
Returns a new ArrayList holding the remaining elements of the enumeration e, in order.
The remaining elements of e, in order, in a new ArrayList.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Enumeration<E>
Returns
Section titled “Returns”ArrayList<E>
max: <
E>(coll,c?) =>E
Returns the largest element of coll by c, or by natural ordering when c is null or omitted; the first
one found on ties. O(n).
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
Comparator<E> | null
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException when empty
Throws
Section titled “Throws”NoSuchElementException if coll is empty
Throws
Section titled “Throws”ClassCastException if natural ordering meets values that cannot be compared
Throws
Section titled “Throws”NullPointerException if natural ordering meets a null element
min: <
E>(coll,c?) =>E
Returns the smallest element of coll by c, or by natural ordering when c is null or omitted; the first
one found on ties. O(n).
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
Comparator<E> | null
Returns
Section titled “Returns”E
Throws
Section titled “Throws”NoSuchElementException when empty
Throws
Section titled “Throws”NoSuchElementException if coll is empty
Throws
Section titled “Throws”ClassCastException if natural ordering meets values that cannot be compared
Throws
Section titled “Throws”NullPointerException if natural ordering meets a null element
nCopies
Section titled “nCopies”nCopies: <
E>(n,o) =>List<E>
Returns an immutable list of n copies of o (which may be null), in O(1) space. nCopies(0, o) is the shared
empty list.
Immutable list of n copies of o (o may be null).
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”number
E
Returns
Section titled “Returns”List<E>
Throws
Section titled “Throws”IllegalArgumentException when n is negative or not an integer
Throws
Section titled “Throws”IllegalArgumentException if n is negative or not an integer
newSequencedSetFromMap
Section titled “newSequencedSetFromMap”newSequencedSetFromMap: <
E>(map) =>SequencedSet<E>
Like newSetFromMap, for a sequenced map: addFirst/addLast use putFirst/putLast, and reversed() is a
set over the reversed map.
Sequenced set view of an empty sequenced map: addFirst/addLast use putFirst/putLast, the rest goes through map.sequencedKeySet().
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”SequencedMap<E, boolean>
Returns
Section titled “Returns”SequencedSet<E>
Throws
Section titled “Throws”IllegalArgumentException if map is not empty
Throws
Section titled “Throws”IllegalArgumentException if map is not empty
newSetFromMap
Section titled “newSetFromMap”newSetFromMap: <
E>(map) =>Set<E>
Returns a set backed by the empty map: add(e) is map.put(e, true), and every other operation goes through
map.keySet(). The set takes on the map’s key semantics, e.g. an identity set over an IdentityHashMap.
Use the map only through the returned set.
Set view of an empty map: add(e) is map.put(e, true) === null, everything else goes through map.keySet().
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Map<E, boolean>
Returns
Section titled “Returns”Set<E>
Throws
Section titled “Throws”IllegalArgumentException if map is not empty
Throws
Section titled “Throws”IllegalArgumentException if map is not empty
replaceAll
Section titled “replaceAll”replaceAll: <
E>(list,oldVal,newVal) =>boolean
Replaces every element of list equal to oldVal (by Objects.equals) with newVal; returns true if any
was replaced. O(n).
Replaces every element equal to oldVal with newVal; true if any was replaced.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
oldVal
Section titled “oldVal”E
newVal
Section titled “newVal”E
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”UnsupportedOperationException if the list does not support set
reverse
Section titled “reverse”reverse: (
list) =>void
Reverses the order of the elements of list in place. O(n).
Parameters
Section titled “Parameters”List<unknown>
Returns
Section titled “Returns”void
Throws
Section titled “Throws”UnsupportedOperationException if the list does not support set
reverseOrder
Section titled “reverseOrder”reverseOrder: <
T>(c?) =>Comparator<T>
Returns a comparator that imposes the reverse of c, or of natural ordering when c is null or omitted.
Reverse natural ordering is one shared instance, and reversing a reversed comparator returns the original.
Reverse of c, or of natural ordering when c is null/omitted (one shared instance). Reversing a reversed comparator gives back the original; reversing natural ordering gives the shared reverse.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Comparator<T> | null
Returns
Section titled “Returns”Comparator<T>
rotate
Section titled “rotate”rotate: (
list,distance) =>void
Rotates list in place by distance: the element at index i moves to (i + distance) mod size(). Any integer
distance works, including negative ones and ones larger than the size. O(n).
Moves the element at i to (i + distance) mod size. Any integer distance (negative, larger than size) is fine.
Parameters
Section titled “Parameters”List<unknown>
distance
Section titled “distance”number
Returns
Section titled “Returns”void
Throws
Section titled “Throws”IllegalArgumentException if distance is not an integer (NaN, fractions, infinities)
Throws
Section titled “Throws”IllegalArgumentException if distance is not an integer
Throws
Section titled “Throws”UnsupportedOperationException if the list does not support set
shuffle
Section titled “shuffle”shuffle: (
list,rnd) =>void
Randomly permutes list in place (Fisher-Yates). O(n). Pass a seeded RandomSource for a reproducible
order; the default is Math.random. A non-random-access list of 5 or more elements is shuffled in an array copy
and written back with its list iterator.
Fisher–Yates shuffle. rnd is a () => number in [0, 1) (default Math.random) or an object with
nextInt(bound) returning an integer in [0, bound), like a RandomGenerator.
Parameters
Section titled “Parameters”List<unknown>
RandomSource = Math.random
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if list or an explicit rnd is null
Throws
Section titled “Throws”NullPointerException if rnd is explicitly null
Throws
Section titled “Throws”UnsupportedOperationException if the list does not support set
singleton
Section titled “singleton”singleton: <
E>(o) =>Set<E>
Returns an immutable set holding only o (which may be null). Value equality with any Set.
Mutators that would change it throw UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Set<E>
singletonList
Section titled “singletonList”singletonList: <
E>(o) =>List<E>
Returns an immutable random-access list holding only o (which may be null). Value equality with any List.
Mutators that would change it throw UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”List<E>
singletonMap
Section titled “singletonMap”singletonMap: <
K,V>(key,value) =>Map<K,V>
Returns an immutable map holding only the mapping key to value (either may be null). Value equality with
any Map.
Mutators that would change it throw UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”Map<K, V>
sort: <
E>(list,c?) =>void
Sorts list stably by c, or by natural ordering when c is null or omitted; delegates to list.sort(c).
O(n log n).
Stable sort; null/omitted comparator = natural ordering.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
Comparator<E> | null
Returns
Section titled “Returns”void
Throws
Section titled “Throws”ClassCastException if natural ordering meets values that cannot be compared
Throws
Section titled “Throws”UnsupportedOperationException if the list does not support set
swap: (
list,i,j) =>void
Swaps the elements at positions i and j (a no-op when they are equal).
Parameters
Section titled “Parameters”List<unknown>
number
number
Returns
Section titled “Returns”void
Throws
Section titled “Throws”IndexOutOfBoundsException
Throws
Section titled “Throws”IndexOutOfBoundsException if i or j is out of range
synchronizedCollection
Section titled “synchronizedCollection”synchronizedCollection: <
E>(c) =>Collection<E>
Returns a delegating view of c with its own identity: equals/hashCode are by identity. JS runs one thread
per realm, so there is nothing to lock; the method exists so ported code keeps working.
Delegating view; equals/hashCode are by identity, as for the reference wrapper.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”Collection<E>
synchronizedList
Section titled “synchronizedList”synchronizedList: <
E>(l) =>List<E>
Returns a delegating view of l (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
Returns
Section titled “Returns”List<E>
synchronizedMap
Section titled “synchronizedMap”synchronizedMap: <
K,V>(m) =>Map<K,V>
Returns a delegating view of m (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”Map<K, V>
Returns
Section titled “Returns”Map<K, V>
synchronizedNavigableMap
Section titled “synchronizedNavigableMap”synchronizedNavigableMap: <
K,V>(m) =>NavigableMap<K,V>
Returns a delegating view of m (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”NavigableMap<K, V>
Returns
Section titled “Returns”NavigableMap<K, V>
synchronizedNavigableSet
Section titled “synchronizedNavigableSet”synchronizedNavigableSet: <
E>(s) =>NavigableSet<E>
Returns a delegating view of s (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”NavigableSet<E>
Returns
Section titled “Returns”NavigableSet<E>
synchronizedSet
Section titled “synchronizedSet”synchronizedSet: <
E>(s) =>Set<E>
Returns a delegating view of s (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Set<E>
Returns
Section titled “Returns”Set<E>
synchronizedSortedMap
Section titled “synchronizedSortedMap”synchronizedSortedMap: <
K,V>(m) =>SortedMap<K,V>
Returns a delegating view of m (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”SortedMap<K, V>
Returns
Section titled “Returns”SortedMap<K, V>
synchronizedSortedSet
Section titled “synchronizedSortedSet”synchronizedSortedSet: <
E>(s) =>SortedSet<E>
Returns a delegating view of s (no locking is needed in JS); every method, equals included, passes through.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”SortedSet<E>
Returns
Section titled “Returns”SortedSet<E>
unmodifiableCollection
Section titled “unmodifiableCollection”unmodifiableCollection: <
E>(c) =>Collection<E>
Returns a read-only live view of c: reads pass through, every mutator (also through iterators) throws
UnsupportedOperationException. equals/hashCode are by identity, not the backing collection’s.
Wrapping a view this method returned returns it unchanged.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Collection<E>
Returns
Section titled “Returns”Collection<E>
unmodifiableList
Section titled “unmodifiableList”unmodifiableList: <
E>(list) =>List<E>
Returns a read-only live view of list, with list equality. subList, reversed() and the iterators are
read-only too; every mutator throws UnsupportedOperationException. Carries the RandomAccess brand
when list does. Wrapping a view this method returned returns it unchanged.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”List<E>
Returns
Section titled “Returns”List<E>
unmodifiableMap
Section titled “unmodifiableMap”unmodifiableMap: <
K,V>(m) =>Map<K,V>
Returns a read-only live view of m, with map equality. keySet(), values() and entrySet() are read-only
(entries reject setValue); every mutator throws UnsupportedOperationException. Wrapping a view this
method returned returns it unchanged.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”Map<K, V>
Returns
Section titled “Returns”Map<K, V>
unmodifiableNavigableMap
Section titled “unmodifiableNavigableMap”unmodifiableNavigableMap: <
K,V>(m) =>NavigableMap<K,V>
Returns a read-only live view of a navigable map; every derived view and entry is read-only too. Every mutator,
pollFirstEntry/pollLastEntry included, throws UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”NavigableMap<K, V>
Returns
Section titled “Returns”NavigableMap<K, V>
unmodifiableNavigableSet
Section titled “unmodifiableNavigableSet”unmodifiableNavigableSet: <
E>(s) =>NavigableSet<E>
Returns a read-only live view of a navigable set; every derived view (descendingSet, subSet, …) is
read-only too. Every mutator, pollFirst/pollLast included, throws UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”NavigableSet<E>
Returns
Section titled “Returns”NavigableSet<E>
unmodifiableSequencedCollection
Section titled “unmodifiableSequencedCollection”unmodifiableSequencedCollection: <
E>(c) =>SequencedCollection<E>
Returns a read-only live view of a sequenced collection; reversed() is read-only too. Every mutator throws
UnsupportedOperationException; equals/hashCode are by identity.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Returns
Section titled “Returns”unmodifiableSequencedMap
Section titled “unmodifiableSequencedMap”unmodifiableSequencedMap: <
K,V>(m) =>SequencedMap<K,V>
Returns a read-only live view of a sequenced map, with map equality; reversed() and the sequenced views are
read-only too. Wrapping an unmodifiable sequenced (or sorted) map returns it.
Unmodifiable view with map equality; wrapping an unmodifiable sequenced (or sorted) map returns it.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”SequencedMap<K, V>
Returns
Section titled “Returns”SequencedMap<K, V>
unmodifiableSequencedSet
Section titled “unmodifiableSequencedSet”unmodifiableSequencedSet: <
E>(s) =>SequencedSet<E>
Returns a read-only live view of a sequenced set, with set equality; reversed() is read-only too. Wrapping an
unmodifiable sequenced (or sorted) set returns it.
Unmodifiable view with set equality; wrapping an unmodifiable sequenced (or sorted) set returns it.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”SequencedSet<E>
Returns
Section titled “Returns”SequencedSet<E>
unmodifiableSet
Section titled “unmodifiableSet”unmodifiableSet: <
E>(s) =>Set<E>
Returns a read-only live view of s, with set equality. Every mutator throws
UnsupportedOperationException. Wrapping a view this method returned returns it unchanged.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”Set<E>
Returns
Section titled “Returns”Set<E>
unmodifiableSortedMap
Section titled “unmodifiableSortedMap”unmodifiableSortedMap: <
K,V>(m) =>SortedMap<K,V>
Returns a read-only live view of a sorted map; sub-map views are read-only too. Every mutator throws UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”SortedMap<K, V>
Returns
Section titled “Returns”SortedMap<K, V>
unmodifiableSortedSet
Section titled “unmodifiableSortedSet”unmodifiableSortedSet: <
E>(s) =>SortedSet<E>
Returns a read-only live view of a sorted set; subSet/headSet/tailSet views are read-only too. Every
mutator throws UnsupportedOperationException.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”SortedSet<E>
Returns
Section titled “Returns”SortedSet<E>