Package-level declarations
This package contains Guava Collections extensions, as well as collections wrappers to provide typed mutability.
Collection Types
The following is a list of guava's collection types, as well as their mutably-typed replacement.
BiMap
An extension of Map that guarantees the uniqueness of its values as well as that of its keys. This is sometimes called an "invertible map," since the restriction on values enables it to support an inverse view -- which is another instance of BiMap.
No wrappers for
BiMapcurrently exist.
Multiset
An extension of Collection that may contain duplicate values like a List, yet has order-independent equality like a Set. One typical use for a multiset is to represent a histogram.
Multiset: A read-only multiset.MutableMultiset: A multiset that supports mutability.
Multimap
A new type, which is similar to Map, but may contain multiple entries with the same key. Some behaviors of Multimap are left unspecified and are provided only by the subtypes mentioned below.
Multimap: A read-only multimap.MutableMultimap: A multimap that supports mutability.
ListMultimap
An extension of Multimap which permits duplicate entries, supports random access of values for a particular key, and has partially order-dependent equality as defined by ListMultimap.equals(Object). ListMultimap takes its name from the fact that the collection of values associated with a given key fulfills the List contract.
ListMultimap: A read-only list multimap.MutableListMultimap: A list multimap that supports mutability.
SetMultimap
An extension of Multimap which has order-independent equality and does not allow duplicate entries; that is, while a key may appear twice in a SetMultimap, each must map to a different value. SetMultimap takes its name from the fact that the collection of values associated with a given key fulfills the Set contract.
SetMultimap: A read-only set multimap.MutableSetMultimap: A set multimap that supports mutability.
SortedSetMultimap
An extension of SetMultimap for which the collection values associated with a given key is a SortedSet.
Types
A Multimap that can hold duplicate key-value pairs and that maintains the insertion ordering of values for a given key.
A collection that holds pairs of objects (keys and values), however each key may be associated with multiple values. Map keys are unique; the map holds only one value for each key.
A generic unordered collection that supports order-independent equality, like Set, but may have duplicate elements. A multiset is also sometimes called a bag.
A Multimap that cannot hold duplicate key-value pairs and that maintains the insertion ordering of values for a given key.
The backing collection type for multiset. Used by the Multiset builder inference methods.
Functions
Adds all elements in this to collection.
Adds all elements in iterator to this. The iterator will be left exhausted: its hasNext method will return false.
Returns true if every element in this satisfies the predicate. If this is empty, true is returned.
Returns true if every element returned by this satisfies the given predicate. If this is empty, true is returned.
Adapts an Iterator to the Enumeration interface.
Returns a string representation of this, with the format [e1, e2, ..., en] (that is, identical to Arrays.toString(Iterables.toArray(iterable))). Note that for most implementations of Collection, collection.toString() also gives the same result, but that behavior is not generally guaranteed.
Returns a string representation of this, with the format [e1, e2, ..., en]. The iterator will be left exhausted: its hasNext method will return false.
Builds a new immutable list-multimap with the given builderAction, using the builder inference api.
Builds a new immutable multimap with the given builderAction, using the builder inference api.
Builds a new immutable multiset with the given builderAction, using the builder inference api.
Builds a new mutable list-multimap with the given builderAction, using the builder inference api.
Builds a new mutable multimap with the given builderAction, using the builder inference api.
Builds a new multiset with the given builderAction, using the builder inference api.
Builds a new mutable set-multimap with the given builderAction, using the builder inference api.
Builds a new immutable set-multimap with the given builderAction, using the builder inference api.
Returns every possible list that can be formed by choosing one element from each of the given lists in order; the "n-ary Cartesian product" of the lists. For example:
Returns a view of the specified CharSequence as a List<Character>, viewing this as a sequence of Unicode code units. The view does not support any modification operations, but reflects any changes to the underlying character sequence.
Returns a view of the specified string as an immutable list of Char values.
Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements of each iterable in iterables sequentially. The source iterators are not polled until necessary.
Combines two iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in other. The source iterators are not polled until necessary.
Combines two iterators into a single iterator. The returned iterator iterates across the elements in this, followed by the elements in iterators sequentially. The source iterators are not polled until necessary.
Combines two iterators into a single iterator. The returned iterator iterates across the elements in this, followed by the elements in other. The source iterators are not polled until necessary.
Combines three iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in a, followed by the elements in b. The source iterators are not polled until necessary.
Combines three iterators into a single iterator. The returned iterator iterates across the elements in this, followed by the elements in a, followed by the elements in b. The source iterators are not polled until necessary.
Combines four iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this, followed by the elements in a, followed by the elements in b, followed by the elements in c. The source iterators are not polled until necessary.
Returns a view of the supplied iterable that wraps each generated Iterator through Iterators.consumingIterator.
Returns a view of the supplied this that removes each element from the supplied this as it is returned.
Returns an iterable whose iterators cycle indefinitely over the elements of this.
Returns an iterable whose iterators cycle indefinitely over the provided elements.
Returns an iterator that cycles indefinitely over the elements of this.
Returns an iterator that cycles indefinitely over the provided elements.
Returns an empty read-only ListMultimap.
Returns an empty read-only Multiset.
Returns an empty read-only SetMultimap.
Returns the elements of this that satisfy a predicate. The returned collection is a live view of this; changes to one affect the other.
Returns a view of this containing all elements that satisfy the input predicate retainIfTrue.
Returns the first element in this that satisfies the given predicate; use this method only when such an element is known to exist. If it is possible that no element will match, use tryFind or find instead.
Returns the first element in this that satisfies the given predicate; use this method only when such an element is known to exist. The iterator will be left exhausted: its hasNext method will return false. If it is possible that no element will match, use Iterator.tryFind or Iterator.find instead.
Combines multiple iterables into a single iterable. The returned iterable has an iterator that traverses the elements in this sequentially. The source iterators are not polled until necessary.
Combines two iterators into a single iterator. The returned iterator iterates across the elements in this sequentially. The source iterators are not polled until necessary.
Adapts an Enumeration to the Iterator interface.
Returns the number of elements in the specified iterable that equal the specified object. This implementation avoids a full iteration when the iterable is a Multiset or Set.
Returns the number of elements in the specified iterator that equal the specified object. The iterator will be left exhausted: its hasNext method will return false.
Returns the element at the specified position in an iterable.
Advances thisposition + 1` times, returning the element at the positionth position.
Returns the element at the specified position in an iterable or a default value otherwise.
Advances thisposition + 1` times, returning the element at the positionth position or a default value otherwise.
Returns the last element of this or defaultValue if the iterable is empty. If this is a List with RandomAccess support, then this operation is guaranteed to be O(1).
Advances this to the end, returning the last element or defaultValue if the iterator is empty and defaultValue is not null.
Returns the next element in this or defaultValue if the iterator is empty. The Iterables analog to this method is Iterables.getFirst.
Returns a view of this containing its first limitSize elements. If this contains fewer than limitSize elements, the returned view contains all of its elements. The returned iterable's iterator supports remove() if this's iterator does.
Returns a view containing the first limitSize elements of this. If this contains fewer than limitSize elements, the returned view contains all of its elements.
Returns an empty read-only ListMultimap.
Returns a new read-only ListMultimap of given elements.
Returns an iterable over the merged contents of all given Iterables in this. Equivalent entries will not be de-duplicated.
Returns an iterator over the merged contents of all given this, traversing every element of the input iterators. Equivalent entries will not be de-duplicated.
Returns an unmodifiable view of the difference of two multisets. In the returned multiset, the count of each element is the result of the zero-truncated subtraction of its count in the second multiset from its count in the first multiset, with elements that would have a count of 0 not included. The iteration order of the returned multiset matches that of the element set of this, with repeated occurrences of the same element appearing consecutively.
Returns an empty new MutableListMultimap.
Returns a new MutableListMultimap with the given elements.
Returns an empty new Multimap.
Returns a new Multimap with the given elements.
Returns a new MutableMultimap with the given elements.
Returns an empty new MutableMultiset.
Returns a new MutableMultiset with the given elements.
Returns an empty new MutableMultimap.
Returns a new MutableMultimap with the given elements.
Returns a Collection of all the permutations of the specified Iterable using naturalOrder for establishing the lexicographical ordering.
Returns a Collection of all the permutations of the specified Iterable using the specified comparator for establishing the lexicographical ordering.
Returns a Collection of all the permutations of the specified Iterable using the specified selector for establishing the lexicographical ordering.
Divides an iterable into unmodifiable sublists of the given size, padding the final iterable with null values if necessary. For example, partitioning an iterable containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e, null]] -- an outer iterable containing two inner lists of three elements each, all in the original order.
Divides an iterator into unmodifiable sublists of the given size, padding the final iterator with null values if necessary. For example, partitioning an iterator containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e, null]] -- an outer iterator containing two inner lists of three elements each, all in the original order.
Divides an iterable into unmodifiable sublists of the given size (the final iterable may be smaller). For example, partitioning an iterable containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer iterable containing two inner lists of three and two elements, all in the original order.
Divides an iterator into unmodifiable sublists of the given size (the final list may be smaller). For example, partitioning an iterator containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer iterator containing two inner lists of three and two elements, all in the original order.
Returns consecutive sublists of a list, each of the same size (the final list may be smaller). For example, partitioning a list containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer list containing two inner lists of three and two elements, all in the original order.
Returns a PeekingIterator backed by the given iterator.
Returns a Collection of all the permutations of the specified Collection.
Returns an unmodifiable view of the sum of two multisets. In the returned multiset, the count of each element is the sum of its counts in the two backing multisets. The iteration order of the returned multiset matches that of the element set of this followed by the members of the element set of other that are not contained in other, with repeated occurrences of the same element appearing consecutively.
Removes, from an iterable, every element that belongs to the provided collection.
Traverses an iterator and removes every element that belongs to the provided collection. The iterator will be left exhausted: its hasNext method will return false.
Removes, from an iterable, every element that satisfies the provided predicate.
Removes every element that satisfies the provided predicate from the iterator. The iterator will be left exhausted: its hasNext method will return false.
Removes, from an iterable, every element that does not belong to the provided collection.
Traverses an iterator and removes every element that does not belong to the provided collection. The iterator will be left exhausted: its hasNext method will return false.
Returns an empty read-only SetMultimap.
Returns a new read-only SetMultimap of given elements.
Returns an iterator containing only this.
Returns a view of this that skips its first numberToSkip elements. If this contains fewer than numberToSkip elements, the returned iterable skips all of its elements.
Transforms a ListMultimap into its immutable guava equivalent
Transforms a Multimap into its immutable guava equivalent
Transforms a Multiset into its immutable guava equivalent
Transforms a MutableListMultimap into its guava equivalent
Transforms a MutableMultimap into its guava equivalent
Transforms a MutableMultiset into its guava equivalent
Transforms a MutableSetMultimap into its guava equivalent
Transforms a SetMultimap into its immutable guava equivalent
Wraps an immutable guava list multimap into a ListMultimap instance.
Wraps an immutable guava multimap into a Multimap instance.
Wraps an immutable guava multiset into a Multiset instance.
Wraps an immutable guava set multimap into a SetMultimap instance.
Wraps a guava list multimap into a MutableListMultimap instance.
Wraps a guava multimap into a MutableMultimap instance.
Wraps a guava multiset into a MutableMultiset instance.
Wraps a guava set multimap into a MutableSetMultimap instance.
Returns a new ListMultimap filled with all elements of this multimap.
Returns a new Multiset filled with all elements of this collection.
Returns a new MutableListMultimap filled with all elements of this multimap.
Returns a new MutableMultimap filled with all elements of this multimap.
Returns a new MutableMultiset filled with all elements of this collection.
Returns a new MutableSetMultimap filled with all elements of this multimap.
Returns a new SetMultimap filled with all elements of this multimap.
Returns a collection that applies function to each element of this. The returned collection is a live view of this; changes to the base collection affects the returned one.
Returns a view containing the result of applying function to each element of this.
Returns a list that applies function to each element of this. The returned list is a transformed view of this; changes to this will be reflected in the returned list and vice versa.
Returns a view containing the result of applying function to each element of fromIterable.
Returns an Optional containing the first element in this that satisfies the given predicate, if such an element exists.
Returns an unmodifiable view of this.
Returns an unmodifiable view of this.