@GwtCompatible(serializable=true, emulated=true) public final class ArrayListMultimap<K,V> extends AbstractListMultimap<K,V>
Multimap
that uses an ArrayList
to store
the values for a given key. A HashMap
associates each key with an
ArrayList
of values.
When iterating through the collections supplied by this class, the ordering of values for a given key agrees with the order in which the values were added.
This multimap allows duplicate key-value pairs. After adding a new
key-value pair equal to an existing key-value pair, the ArrayListMultimap
will contain entries for both the new value and the old
value.
Keys and values may be null. All optional multimap methods are supported, and all returned views are modifiable.
The lists returned by AbstractListMultimap.get(K)
, AbstractListMultimap.removeAll(java.lang.Object)
, and AbstractListMultimap.replaceValues(K, java.lang.Iterable<? extends V>)
all implement RandomAccess
.
This class is not threadsafe when any concurrent operations update the
multimap. Concurrent read operations will work correctly. To allow concurrent
update operations, wrap your multimap with a call to Multimaps.synchronizedListMultimap(com.google.common.collect.ListMultimap<K, V>)
.
See the Guava User Guide article on
Multimap
.
AbstractMapBasedMultimap.NavigableAsMap, AbstractMapBasedMultimap.NavigableKeySet, AbstractMapBasedMultimap.WrappedNavigableSet
AbstractMultimap.Values
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_VALUES_PER_KEY |
(package private) int |
expectedValuesPerKey |
private static long |
serialVersionUID |
Modifier | Constructor and Description |
---|---|
private |
ArrayListMultimap() |
private |
ArrayListMultimap(int expectedKeys,
int expectedValuesPerKey) |
private |
ArrayListMultimap(Multimap<? extends K,? extends V> multimap) |
Modifier and Type | Method and Description |
---|---|
static <K,V> ArrayListMultimap<K,V> |
create()
Creates a new, empty
ArrayListMultimap with the default initial
capacities. |
static <K,V> ArrayListMultimap<K,V> |
create(int expectedKeys,
int expectedValuesPerKey)
Constructs an empty
ArrayListMultimap with enough capacity to hold
the specified numbers of keys and values without resizing. |
static <K,V> ArrayListMultimap<K,V> |
create(Multimap<? extends K,? extends V> multimap)
Constructs an
ArrayListMultimap with the same mappings as the
specified multimap. |
(package private) java.util.List<V> |
createCollection()
Creates a new, empty
ArrayList to hold the collection of values for
an arbitrary key. |
private void |
readObject(java.io.ObjectInputStream stream) |
void |
trimToSize()
Reduces the memory used by this
ArrayListMultimap , if feasible. |
private void |
writeObject(java.io.ObjectOutputStream stream) |
asMap, createUnmodifiableEmptyCollection, equals, get, put, removeAll, replaceValues
backingMap, clear, containsKey, createAsMap, createCollection, createKeySet, entries, entryIterator, setMap, size, unmodifiableCollectionSubclass, valueIterator, values, wrapCollection
containsEntry, containsValue, createEntries, createKeys, createValues, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
clear, containsEntry, containsKey, containsValue, entries, hashCode, isEmpty, keys, keySet, putAll, putAll, remove, size, values
private static final int DEFAULT_VALUES_PER_KEY
transient int expectedValuesPerKey
@GwtIncompatible private static final long serialVersionUID
private ArrayListMultimap()
private ArrayListMultimap(int expectedKeys, int expectedValuesPerKey)
public static <K,V> ArrayListMultimap<K,V> create()
ArrayListMultimap
with the default initial
capacities.public static <K,V> ArrayListMultimap<K,V> create(int expectedKeys, int expectedValuesPerKey)
ArrayListMultimap
with enough capacity to hold
the specified numbers of keys and values without resizing.expectedKeys
- the expected number of distinct keysexpectedValuesPerKey
- the expected average number of values per keyjava.lang.IllegalArgumentException
- if expectedKeys
or expectedValuesPerKey
is negativepublic static <K,V> ArrayListMultimap<K,V> create(Multimap<? extends K,? extends V> multimap)
ArrayListMultimap
with the same mappings as the
specified multimap.multimap
- the multimap whose contents are copied to this multimapjava.util.List<V> createCollection()
ArrayList
to hold the collection of values for
an arbitrary key.createCollection
in class AbstractListMultimap<K,V>
public void trimToSize()
ArrayListMultimap
, if feasible.@GwtIncompatible private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
java.io.IOException
@GwtIncompatible private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException