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

Mapmap(Map accumulator, Key key, Value value)
Adds a entry to a map namely (key,value).
accumulator.put(key, value);
return accumulator;
Stringmap(Map outcomeMapping, String line, int firstTabIdx)
map
String s = line.substring(0, firstTabIdx);
Integer integer = outcomeMapping.get(s);
if (integer == null) {
    return s;
return integer.toString();
Mapmap(Object key, Object value)
map
Map map = new HashMap();
map.put(key, value);
return map;
Mapmap(Object obj)
Readability method for casting.
return (Map<String, Object>) obj;
Mapmap(Object... args)
map
if (args.length % 2 != 0)
    throw new IllegalArgumentException("Length of arguments must be a multiple of 2");
else if (args.length == 0)
    return Collections.emptyMap();
Map<K, V> ret = new HashMap<>(args.length / 2);
for (int idx = 0; idx < args.length; idx += 2) {
    ret.put((K) args[idx], (V) args[idx + 1]);
return ret;
Mapmap(Object... data)
map
Map<K, V> map = new HashMap<K, V>(data.length + 2);
for (int i = 1; i < data.length; i += 2) {
    map.put((K) data[i - 1], (V) data[i]);
return map;
Mapmap(Object... data)
This is useful to create a map of object in declarative way.
Map<K, V> map = new HashMap<K, V>(data.length + 2);
for (int i = 1; i < data.length; i += 2) {
    map.put((K) data[i - 1], (V) data[i]);
return map;