Top Description Fields Constructors Methods
com.google.common.collect

public final Class ArrayListMultimap<K extends @Nullable Object, V extends @Nullable Object>

extends ArrayListMultimapGwtSerializationDependencies<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.collect.CollectPreconditions.checkNonnegative

Implementation of 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 get, removeAll, and replaceValues all implement java.util.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.

See the Guava User Guide article on Multimap.

Author
Jared Levy
Since
2.0

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv transient int
private static final long

Constructor Summary

AccessConstructor and Description
private
private
ArrayListMultimap(int expectedKeys, int expectedValuesPerKey)

private
ArrayListMultimap(Multimap<? extends K, ? extends V> multimap)

Method Summary

Modifier and TypeMethod and Description
public static <K extends @Nullable Object, V extends @Nullable Object> ArrayListMultimap<K, V>
create()

Creates a new, empty ArrayListMultimap with the default initial capacities.

public static <K extends @Nullable Object, V extends @Nullable Object> ArrayListMultimap<K, V>
create(int
the expected number of distinct keys
expectedKeys
,
int
the expected average number of values per key
expectedValuesPerKey
)

Constructs an empty ArrayListMultimap with enough capacity to hold the specified numbers of keys and values without resizing.

public static <K extends @Nullable Object, V extends @Nullable Object> ArrayListMultimap<K, V>
create(Multimap<? extends K, ? extends V>
the multimap whose contents are copied to this multimap
multimap
)

Constructs an ArrayListMultimap with the same mappings as the specified multimap.

pack-priv List<V>
createCollection()

Implements abstract com.google.common.collect.AbstractListMultimap.createCollection.

Creates a new, empty ArrayList to hold the collection of values for an arbitrary key.
private void
public void
trimToSize()

Deprecated For a ListMultimap that automatically trims to size, use ImmutableListMultimap.
Reduces the memory used by this ArrayListMultimap, if feasible.
private void

Field Detail

DEFAULT_VALUES_PER_KEYback to summary
private static final int DEFAULT_VALUES_PER_KEY
expectedValuesPerKeyback to summary
pack-priv transient int expectedValuesPerKey
Annotations
@VisibleForTesting
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.google.common.collect.AbstractListMultimap.serialVersionUID.

Annotations
@GwtIncompatible
@J2ktIncompatible

Constructor Detail

ArrayListMultimapback to summary
private ArrayListMultimap()
ArrayListMultimapback to summary
private ArrayListMultimap(int expectedKeys, int expectedValuesPerKey)
ArrayListMultimapback to summary
private ArrayListMultimap(Multimap<? extends K, ? extends V> multimap)

Method Detail

createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> ArrayListMultimap<K, V> create()

Creates a new, empty ArrayListMultimap with the default initial capacities.

This method will soon be deprecated in favor of MultimapBuilder.hashKeys().arrayListValues().build().

createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> 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.

This method will soon be deprecated in favor of MultimapBuilder.hashKeys(expectedKeys).arrayListValues(expectedValuesPerKey).build().

Parameters
expectedKeys:int

the expected number of distinct keys

expectedValuesPerKey:int

the expected average number of values per key

Exceptions
IllegalArgumentException:
if expectedKeys or expectedValuesPerKey is negative
createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> ArrayListMultimap<K, V> create(Multimap<? extends K, ? extends V> multimap)

Constructs an ArrayListMultimap with the same mappings as the specified multimap.

This method will soon be deprecated in favor of MultimapBuilder.hashKeys().arrayListValues().build(multimap).

Parameters
multimap:Multimap<? extends K, ? extends V>

the multimap whose contents are copied to this multimap

createCollectionback to summary
pack-priv List<V> createCollection()

Implements abstract com.google.common.collect.AbstractListMultimap.createCollection.

Creates a new, empty ArrayList to hold the collection of values for an arbitrary key.

Returns:List<V>

Doc from com.google.common.collect.AbstractMapBasedMultimap.createCollection.

an empty collection of values

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
Annotations
@GwtIncompatible
@J2ktIncompatible
trimToSizeback to summary
public void trimToSize()

Deprecated

For a ListMultimap that automatically trims to size, use ImmutableListMultimap. If you need a mutable collection, remove the trimToSize call, or switch to a HashMap<K, ArrayList<V>>.

Reduces the memory used by this ArrayListMultimap, if feasible.

Annotations
@Deprecated
writeObjectback to summary
private void writeObject(ObjectOutputStream stream) throws IOException
Annotations
@GwtIncompatible
@J2ktIncompatible
Serial data
expectedValuesPerKey, number of distinct keys, and then for each distinct key: the key, number of values for that key, and the key's values