public final class Maps extends Object
Map
instances (including instances of
SortedMap
, BiMap
, etc.). Also see this class's counterparts
Lists
, Sets
and Queues
.
See the Guava User Guide article on
Maps
.
Modifier and Type | Method and Description |
---|---|
static <K,V> Map.Entry<K,V> |
immutableEntry(K key,
V value)
Returns an immutable map entry with the specified key and value.
|
static <K,V> HashMap<K,V> |
newHashMapWithExpectedSize(int expectedSize)
Creates a
HashMap instance, with a high enough "initial capacity"
that it should hold expectedSize elements without growth. |
public static <K,V> HashMap<K,V> newHashMapWithExpectedSize(int expectedSize)
HashMap
instance, with a high enough "initial capacity"
that it should hold expectedSize
elements without growth.
This behavior cannot be broadly guaranteed, but it is observed to be true
for OpenJDK 1.6. It also can't be guaranteed that the method isn't
inadvertently oversizing the returned map.expectedSize
- the number of elements you expect to add to the
returned mapHashMap
with enough capacity to hold expectedSize
elements without resizingIllegalArgumentException
- if expectedSize
is negativepublic static <K,V> Map.Entry<K,V> immutableEntry(K key, V value)
Map.Entry.setValue(V)
operation throws an UnsupportedOperationException
.
The returned entry is serializable.
key
- the key to be associated with the returned entryvalue
- the value to be associated with the returned entryCopyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.