public class MapUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <K,V> HashMap<K,V> |
newHashMap()
Creates a mutable, empty
HashMap instance. |
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. |
static <K,V> LinkedHashMap<K,V> |
newLinkedHashMap()
Creates a mutable, empty, insertion-ordered
LinkedHashMap instance. |
static <K,V> LinkedHashMap<K,V> |
newLinkedHashMapWithExpectedSize(int expectedSize)
Creates a
LinkedHashMap instance, with a high enough "initial capacity" that it
should hold expectedSize elements without growth. |
static <K extends Comparable,V> |
newTreeMap()
Creates a mutable, empty
TreeMap instance using the natural ordering of its
elements. |
public static <K,V> HashMap<K,V> newHashMap()
HashMap instance.
Note: if mutability is not required, use ImmutableMap.of() instead.
Note: if K is an enum type, use newEnumMap instead.
Note for Java 7 and later: this method is now unnecessary and should be treated as
deprecated. Instead, use the HashMap constructor directly, taking advantage of the new
"diamond" syntax.
HashMappublic static <K extends Comparable,V> TreeMap<K,V> newTreeMap()
TreeMap instance using the natural ordering of its
elements.
Note: if mutability is not required, use ImmutableSortedMap.of() instead.
Note for Java 7 and later: this method is now unnecessary and should be treated as
deprecated. Instead, use the TreeMap constructor directly, taking advantage of the new
"diamond" syntax.
TreeMappublic 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.7. It also can't be guaranteed that the method
isn't inadvertently oversizing the returned map.expectedSize - the number of entries you expect to add to the returned mapHashMap with enough capacity to hold expectedSize entries
without resizingIllegalArgumentException - if expectedSize is negativepublic static <K,V> LinkedHashMap<K,V> newLinkedHashMap()
LinkedHashMap instance.
Note: if mutability is not required, use ImmutableMap.of() instead.
Note for Java 7 and later: this method is now unnecessary and should be treated as
deprecated. Instead, use the LinkedHashMap constructor directly, taking advantage of
the new "diamond" syntax.
LinkedHashMappublic static <K,V> LinkedHashMap<K,V> newLinkedHashMapWithExpectedSize(int expectedSize)
LinkedHashMap 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.7. It also can't be guaranteed
that the method isn't inadvertently oversizing the returned map.expectedSize - the number of entries you expect to add to the returned mapLinkedHashMap with enough capacity to hold expectedSize
entries without resizingIllegalArgumentException - if expectedSize is negativeCopyright © 2018–2024 Alibaba Group. All rights reserved.