Java Utililty Methods Map Create

List of utility methods to do Map Create

Description

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

Method

MapcreateMap()
create Map
return new HashMap<K, V>();
MapcreateMap(boolean full)
create Map
final Map<String, Object> map = new HashMap<>();
map.put("mongoUri", URI);
map.put("database", DB);
if (full) {
    map.put("collection", COLL);
    map.put("batchSize", BATCH_SIZE);
    map.put("batchTimeMs", BATCH_TIME);
return map;
MapcreateMap(int len)
create Map
if (len < 1) {
    return new HashMap();
return new HashMap(len);
MapcreateMap(Iterable> entries)
Initialize a map using a variable number of Entry objects as input
Map<K, V> map = new HashMap<K, V>();
for (Entry<K, V> entry : entries)
    map.put(entry.getKey(), entry.getValue());
return map;
MapcreateMap(K k1, V v1)
create Map
Map<K, V> m = new HashMap<>();
m.put(k1, v1);
return Collections.unmodifiableMap(m);
MapcreateMap(K[] keys, V[] values)
create Map
assert keys.length == values.length : "Lengths of keys and values should be the same";
Map<K, V> res = new HashMap<>(keys.length);
for (int i = 0; i < keys.length; i++)
    res.put(keys[i], values[i]);
return res;
MapcreateMap(List keys, List values)
create Map
Map<A, B> map = new HashMap<A, B>();
for (int i = 0; i < keys.size(); i++) {
    if (i == values.size()) {
        break;
    map.put(keys.get(i), values.get(i));
return map;
...
MapcreateMap(List keys, List values)
Create a Map from a List of keys and a List of values
if (keys == null || values == null || keys.size() != values.size()) {
    throw new IllegalArgumentException("Keys and Values cannot be null and must be the same size");
Map<Object, Object> newMap = new HashMap<Object, Object>();
for (int i = 0; i < keys.size(); i++) {
    newMap.put(keys.get(i), values.get(i));
return newMap;
...
MapcreateMap(Map map)
create Map
if (map == null) {
    return null;
Map<K, V> result = new HashMap<K, V>();
result.putAll(map);
return result;
MapcreateMap(Object keys[], Object values[])
create Map
Map map = new HashMap();
if (keys.length != values.length)
    return map;
for (int i = 0; i < keys.length; i++)
    map.put(keys[i], values[i]);
return map;