@CheckReturnValue @ParametersAreNonnullByDefault
Package com.google.common.collect
Collection interfaces and implementations, and other utilities for collections. This package is a
part of the open-source Guava library.
The classes in this package include:
Immutable collections
These are collections whose contents will never change. They also offer a few additional guarantees (seeImmutableCollection
for details). Implementations are available for both
the JDK collection types and the Guava collection types (listed below).
Collection types
Multimap
- A new type, which is similar to
Map
, but may contain multiple entries with the same key. Some behaviors ofMultimap
are left unspecified and are provided only by the subtypes mentioned below. 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 byListMultimap.equals(Object)
.ListMultimap
takes its name from the fact that the collection of values associated with a given key fulfills theList
contract. 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 aSetMultimap
, 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 theSet
contract. SortedSetMultimap
- An extension of
SetMultimap
for which the collection values associated with a given key is aSortedSet
. 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 ofBiMap
. Table
- A new type, which is similar to
Map
, but which indexes its values by an ordered pair of keys, a row key and column key. Multiset
- An extension of
Collection
that may contain duplicate values like aList
, yet has order-independent equality like aSet
. One typical use for a multiset is to represent a histogram. ClassToInstanceMap
- An extension of
Map
that associates a raw type with an instance of that type.
Ranges
Classes of static utility methods
Collections2
Comparators
Iterables
Iterators
Lists
Maps
MoreCollectors
Multimaps
Multisets
ObjectArrays
Queues
Sets
Streams
Tables
Abstract implementations
Forwarding collections
We provide implementations of collections that forward all method calls to a delegate collection by default. Subclasses can override one or more methods to implement the decorator pattern. For an example, seeForwardingCollection
.
Other
-
Interface Summary Interface Description BiMap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A bimap (or "bidirectional map") is a map that preserves the uniqueness of its values as well as that of its keys.ClassToInstanceMap<B extends @Nullable java.lang.Object> A map, each entry of which maps a Java raw type to an instance of that type.Interner<E> Provides similar behavior toString.intern()
for any immutable type.ListMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> AMultimap
that can hold duplicate key-value pairs and that maintains the insertion ordering of values for a given key.MapDifference<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> An object representing the differences between two maps.MapDifference.ValueDifference<V extends @Nullable java.lang.Object> A difference between the mappings from two maps with the same key.Maps.EntryTransformer<K extends @Nullable java.lang.Object,V1 extends @Nullable java.lang.Object,V2 extends @Nullable java.lang.Object> A transformation of the value of a key-value pair, using both key and value as inputs.Multimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A collection that maps keys to values, similar toMap
, but in which each key may be associated with multiple values.Multiset<E extends @Nullable java.lang.Object> A collection that supports order-independent equality, likeSet
, but may have duplicate elements.Multiset.Entry<E extends @Nullable java.lang.Object> An unmodifiable element-count pair for a multiset.PeekingIterator<E extends @Nullable java.lang.Object> An iterator that supports a one-element lookahead while iterating.RangeMap<K extends java.lang.Comparable,V> A mapping from disjoint nonempty ranges to non-null values.RangeSet<C extends java.lang.Comparable> RowSortedTable<R extends @Nullable java.lang.Object,C extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> Interface that extendsTable
and whose rows are sorted.SetMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> AMultimap
that cannot hold duplicate key-value pairs.SortedMapDifference<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> An object representing the differences between two sorted maps.SortedMultiset<E extends @Nullable java.lang.Object> AMultiset
which maintains the ordering of its elements, according to either their natural order or an explicitComparator
.SortedSetMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> ASetMultimap
whose set of values for a given key are kept sorted; that is, they comprise aSortedSet
.Streams.DoubleFunctionWithIndex<R extends @Nullable java.lang.Object> An analogue ofDoubleFunction
also accepting an index.Streams.FunctionWithIndex<T extends @Nullable java.lang.Object,R extends @Nullable java.lang.Object> An analogue ofFunction
also accepting an index.Streams.IntFunctionWithIndex<R extends @Nullable java.lang.Object> An analogue ofIntFunction
also accepting an index.Streams.LongFunctionWithIndex<R extends @Nullable java.lang.Object> An analogue ofLongFunction
also accepting an index.Table<R extends @Nullable java.lang.Object,C extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A collection that associates an ordered pair of keys, called a row key and a column key, with a single value.Table.Cell<R extends @Nullable java.lang.Object,C extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> Row key / column key / value triplet corresponding to a mapping in a table. -
Class Summary Class Description AbstractIterator<T extends @Nullable java.lang.Object> This class provides a skeletal implementation of theIterator
interface, to make this interface easier to implement for certain types of data sources.AbstractSequentialIterator<T> This class provides a skeletal implementation of theIterator
interface for sequences whose next element can always be derived from the previous element.ArrayListMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> Implementation ofMultimap
that uses anArrayList
to store the values for a given key.ArrayTable<R,C,V> Fixed-sizeTable
implementation backed by a two-dimensional array.Collections2 Provides static methods for working withCollection
instances.Comparators Provides static methods for working withComparator
instances.ComparisonChain A utility for performing a chained comparison statement.ConcurrentHashMultiset<E> A multiset that supports concurrent modifications and that provides atomic versions of mostMultiset
operations (exceptions where noted).ContiguousSet<C extends java.lang.Comparable> A sorted set of contiguous values in a givenDiscreteDomain
.DiscreteDomain<C extends java.lang.Comparable> A descriptor for a discreteComparable
domain such as allInteger
instances.EnumBiMap<K extends java.lang.Enum<K>,V extends java.lang.Enum<V>> ABiMap
backed by twoEnumMap
instances.EnumHashBiMap<K extends java.lang.Enum<K>,V extends @Nullable java.lang.Object> ABiMap
backed by anEnumMap
instance for keys-to-values, and aHashMap
instance for values-to-keys.EnumMultiset<E extends java.lang.Enum<E>> Multiset implementation specialized for enum elements, supporting all single-element operations in O(1).EvictingQueue<E> A non-blocking queue which automatically evicts elements from the head of the queue when attempting to add new elements onto the queue and it is full.FluentIterable<E extends @Nullable java.lang.Object> A discouraged (but not deprecated) precursor to Java's superiorStream
library.ForwardingBlockingDeque<E> Deprecated. This class has moved tocom.google.common.util.concurrent
.ForwardingCollection<E extends @Nullable java.lang.Object> A collection which forwards all its method calls to another collection.ForwardingConcurrentMap<K,V> A concurrent map which forwards all its method calls to another concurrent map.ForwardingDeque<E extends @Nullable java.lang.Object> A deque which forwards all its method calls to another deque.ForwardingIterator<T extends @Nullable java.lang.Object> An iterator which forwards all its method calls to another iterator.ForwardingList<E extends @Nullable java.lang.Object> A list which forwards all its method calls to another list.ForwardingListIterator<E extends @Nullable java.lang.Object> A list iterator which forwards all its method calls to another list iterator.ForwardingListMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A list multimap which forwards all its method calls to another list multimap.ForwardingMap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A map which forwards all its method calls to another map.ForwardingMapEntry<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A map entry which forwards all its method calls to another map entry.ForwardingMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A multimap which forwards all its method calls to another multimap.ForwardingMultiset<E extends @Nullable java.lang.Object> A multiset which forwards all its method calls to another multiset.ForwardingNavigableMap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A navigable map which forwards all its method calls to another navigable map.ForwardingNavigableSet<E extends @Nullable java.lang.Object> A navigable set which forwards all its method calls to another navigable set.ForwardingObject An abstract base class for implementing the decorator pattern.ForwardingQueue<E extends @Nullable java.lang.Object> A queue which forwards all its method calls to another queue.ForwardingSet<E extends @Nullable java.lang.Object> A set which forwards all its method calls to another set.ForwardingSetMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A set multimap which forwards all its method calls to another set multimap.ForwardingSortedMap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A sorted map which forwards all its method calls to another sorted map.ForwardingSortedMultiset<E extends @Nullable java.lang.Object> A sorted multiset which forwards all its method calls to another sorted multiset.ForwardingSortedSet<E extends @Nullable java.lang.Object> A sorted set which forwards all its method calls to another sorted set.ForwardingSortedSetMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A sorted set multimap which forwards all its method calls to another sorted set multimap.ForwardingTable<R extends @Nullable java.lang.Object,C extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> A table which forwards all its method calls to another table.HashBasedTable<R,C,V> Implementation ofTable
using linked hash tables.HashBiMap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> ABiMap
backed by two hash tables.HashMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> Implementation ofMultimap
using hash tables.HashMultiset<E extends @Nullable java.lang.Object> Multiset implementation backed by aHashMap
.ImmutableBiMap<K,V> ABiMap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableBiMap.Builder<K,V> A builder for creating immutable bimap instances, especiallypublic static final
bimaps ("constant bimaps").ImmutableClassToInstanceMap<B> AClassToInstanceMap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableClassToInstanceMap.Builder<B> A builder for creating immutable class-to-instance maps.ImmutableCollection<E> ACollection
whose contents will never change, and which offers a few additional guarantees detailed below.ImmutableCollection.Builder<E> Abstract base class for builders ofImmutableCollection
types.ImmutableList<E> AList
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableList.Builder<E> A builder for creating immutable list instances, especiallypublic static final
lists ("constant lists").ImmutableListMultimap<K,V> AListMultimap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableListMultimap.Builder<K,V> A builder for creating immutableListMultimap
instances, especiallypublic static final
multimaps ("constant multimaps").ImmutableMap<K,V> AMap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableMap.Builder<K,V> A builder for creating immutable map instances, especiallypublic static final
maps ("constant maps").ImmutableMultimap<K,V> AMultimap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableMultimap.Builder<K,V> A builder for creating immutable multimap instances, especiallypublic static final
multimaps ("constant multimaps").ImmutableMultiset<E> AMultiset
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableMultiset.Builder<E> A builder for creating immutable multiset instances, especiallypublic static final
multisets ("constant multisets").ImmutableRangeMap<K extends java.lang.Comparable<?>,V> ARangeMap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableRangeMap.Builder<K extends java.lang.Comparable<?>,V> A builder for immutable range maps.ImmutableRangeSet<C extends java.lang.Comparable> ARangeSet
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableRangeSet.Builder<C extends java.lang.Comparable<?>> A builder for immutable range sets.ImmutableSet<E> ASet
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableSet.Builder<E> A builder for creatingImmutableSet
instances.ImmutableSetMultimap<K,V> ASetMultimap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableSetMultimap.Builder<K,V> A builder for creating immutableSetMultimap
instances, especiallypublic static final
multimaps ("constant multimaps").ImmutableSortedMap<K,V> ANavigableMap
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableSortedMap.Builder<K,V> A builder for creating immutable sorted map instances, especiallypublic static final
maps ("constant maps").ImmutableSortedMultiset<E> ASortedMultiset
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableSortedMultiset.Builder<E> A builder for creating immutable multiset instances, especiallypublic static final
multisets ("constant multisets").ImmutableSortedSet<E> ANavigableSet
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableSortedSet.Builder<E> A builder for creating immutable sorted set instances, especiallypublic static final
sets ("constant sets"), with a given comparator.ImmutableTable<R,C,V> ATable
whose contents will never change, with many other important properties detailed atImmutableCollection
.ImmutableTable.Builder<R,C,V> A builder for creating immutable table instances, especiallypublic static final
tables ("constant tables").Interners Contains static methods pertaining to instances ofInterner
.Interners.InternerBuilder Builder forInterner
instances.Iterables An assortment of mainly legacy static utility methods that operate on or return objects of typeIterable
.Iterators This class contains static utility methods that operate on or return objects of typeIterator
.LinkedHashMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> Implementation ofMultimap
that does not allow duplicate key-value entries and that returns collections whose iterators follow the ordering in which the data was added to the multimap.LinkedHashMultiset<E extends @Nullable java.lang.Object> AMultiset
implementation with predictable iteration order.LinkedListMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> An implementation ofListMultimap
that supports deterministic iteration order for both keys and values.Lists Static utility methods pertaining toList
instances.MapMaker A builder ofConcurrentMap
instances that can have keys or values automatically wrapped in weak references.Maps MinMaxPriorityQueue<E> A double-ended priority queue, which provides constant-time access to both its least element and its greatest element, as determined by the queue's specified comparator.MinMaxPriorityQueue.Builder<B> The builder class used in creation of min-max priority queues.MoreCollectors Collectors not present injava.util.stream.Collectors
that are not otherwise associated with acom.google.common
type.MultimapBuilder<K0 extends @Nullable java.lang.Object,V0 extends @Nullable java.lang.Object> An immutable builder forMultimap
instances, letting you independently select the desired behaviors (for example, ordering) of the backing map and value-collections.MultimapBuilder.ListMultimapBuilder<K0 extends @Nullable java.lang.Object,V0 extends @Nullable java.lang.Object> A specialization ofMultimapBuilder
that generatesListMultimap
instances.MultimapBuilder.MultimapBuilderWithKeys<K0 extends @Nullable java.lang.Object> An intermediate stage in aMultimapBuilder
in which the key-value collection map implementation has been specified, but the value collection implementation has not.MultimapBuilder.SetMultimapBuilder<K0 extends @Nullable java.lang.Object,V0 extends @Nullable java.lang.Object> A specialization ofMultimapBuilder
that generatesSetMultimap
instances.MultimapBuilder.SortedSetMultimapBuilder<K0 extends @Nullable java.lang.Object,V0 extends @Nullable java.lang.Object> A specialization ofMultimapBuilder
that generatesSortedSetMultimap
instances.Multimaps Provides static methods acting on or generating aMultimap
.Multisets Provides static utility methods for creating and working withMultiset
instances.MutableClassToInstanceMap<B extends @Nullable java.lang.Object> A mutable class-to-instance map backed by an arbitrary user-provided map.ObjectArrays Static utility methods pertaining to object arrays.Ordering<T extends @Nullable java.lang.Object> A comparator, with additional methods to support common operations.Queues Static utility methods pertaining toQueue
andDeque
instances.Range<C extends java.lang.Comparable> A range (or "interval") defines the boundaries around a contiguous span of values of someComparable
type; for example, "integers from 1 to 100 inclusive." Note that it is not possible to iterate over these contained values.Sets Static utility methods pertaining toSet
instances.Sets.SetView<E extends @Nullable java.lang.Object> An unmodifiable view of a set which may be backed by other sets; this view will change as the backing sets do.Streams Static utility methods related toStream
instances.Tables Provides static methods that involve aTable
.TreeBasedTable<R,C,V> Implementation ofTable
whose row keys and column keys are ordered by their natural ordering or by supplied comparators.TreeMultimap<K extends @Nullable java.lang.Object,V extends @Nullable java.lang.Object> Implementation ofMultimap
whose keys and values are ordered by their natural ordering or by supplied comparators.TreeMultiset<E extends @Nullable java.lang.Object> A multiset which maintains the ordering of its elements, according to either their natural order or an explicitComparator
.TreeRangeMap<K extends java.lang.Comparable,V> An implementation ofRangeMap
based on aTreeMap
, supporting all optional operations.TreeRangeSet<C extends java.lang.Comparable<?>> An implementation ofRangeSet
backed by aTreeMap
.TreeTraverser<T> Deprecated. UseTraverser
instead.UnmodifiableIterator<E extends @Nullable java.lang.Object> An iterator that does not supportUnmodifiableIterator.remove()
.UnmodifiableListIterator<E extends @Nullable java.lang.Object> A list iterator that does not supportUnmodifiableIterator.remove()
,UnmodifiableListIterator.add(E)
, orUnmodifiableListIterator.set(E)
. -
Enum Summary Enum Description BoundType Indicates whether an endpoint of some range is contained in the range itself ("closed") or not ("open"). -
Exception Summary Exception Description ComputationException Deprecated. This exception is no longer thrown bycom.google.common
.