Java Utililty Methods HashMap Create

List of utility methods to do HashMap Create

Description

The list of methods to do HashMap Create are organized into topic(s).

Method

HashMapnewHashMap(K[] keys, V[] values)
new Hash Map
if (keys.length > values.length) {
    throw new IllegalArgumentException("Values is less than keys");
HashMap<K, V> map = new HashMap<>();
for (int i = 0; i < keys.length; i++) {
    map.put(keys[i], values[i]);
return map;
...
MapnewHashMap(Map.Entry... entries)
new Hash Map
Map<K, V> map = new HashMap<K, V>();
for (Map.Entry<K, V> entry : entries) {
    map.put(entry.getKey(), entry.getValue());
return map;
HashMapnewHashMap(Map m)
new Hash Map
return new HashMap<K, V>(m);
HashMapnewHashMap(Object... kv)
Construct a new HashMap with a list of key/value pairs as arguments.
int length = kv.length;
if (length % 2 != 0)
    throw new IllegalArgumentException("Mismatched keys and values");
HashMap<K, V> m = new HashMap<>();
fillMap(m, kv);
return m;
MapnewHashMap(T key, U value)
new Hash Map
Map<T, U> m = new HashMap<T, U>();
m.put(key, value);
return m;
HashMapnewHashMapWithCapacity(int expectedSize, float loadFactor)
new Hash Map With Capacity
int finalSize = (int) ((double) expectedSize / loadFactor + 1.0F);
return new HashMap<K, V>(finalSize, loadFactor);
MaptoHashMap(Entry[] entries)
to Hash Map
return populate(new HashMap<String, String>(), entries);
HashMaptoHashMap(ArrayList list, int beginId)
to Hash Map
HashMap<String, Integer> map = new HashMap<String, Integer>(list.size());
for (int i = 0; i < list.size(); i++)
    map.put(list.get(i), i + beginId);
return map;
HashMaptoHashMap(final Map map)
to Hash Map
if (map instanceof HashMap) {
    return (HashMap<K, V>) map;
} else {
    return new HashMap<>(map);
HashMaptoHashMapStrObj(Object object)
replacement of casting as from Object to HashMap<String, Object> without annoying warning.
if (object == null) {
    return null;
return (HashMap<String, Object>) object;