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

MapbuildMap(K key, V value)
build Map
Map<K, V> map = new HashMap<K, V>();
map.put(key, value);
return map;
MapbuildMap(K key1, V value1)
Build Map with 1 pair.
Map<K, V> map = new HashMap<K, V>(1);
map.put(key1, value1);
return map;
voidbuildMap(List a, Map coeffs)
build Map
for (T t : a) {
    Integer coeff = coeffs.get(t);
    if (coeff == null) {
        coeffs.put(t, 1);
    } else {
        coeffs.put(t, coeff + 1);
MapbuildMap(Object key, Object value)
build Map
return buildMap(key, value, null, null, null, null, null, null, null, null, null, null);
MapbuildMap(Object... data)
Builds a map out of parameters
HashMap<String, Object> result = new HashMap<String, Object>();
if (data.length % 2 != 0)
    throw new IllegalArgumentException("Odd number of arguments");
String key = null;
Integer step = -1;
for (Object value : data) {
    step++;
    switch (step % 2) {
...
MapbuildMap(String... keysAndValues)
build Map
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < keysAndValues.length;) {
    map.put(keysAndValues[i], keysAndValues[i + 1]);
    i += 2;
return map;
MapbuildMap(String... keyValuePairs)
Builds a map of key/value pairs.
if (keyValuePairs.length % 2 != 0)
    throw new IllegalArgumentException("keyValuePairs array not dividable by 2 (key + value)");
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < keyValuePairs.length; i += 2) {
    map.put(keyValuePairs[i], keyValuePairs[i + 1]);
return map;
MapcreateMap()
create Map
return createMap(Collections.EMPTY_MAP);
MapcreateMap()
create Map
Map<String, String[]> result = new HashMap<String, String[]>();
result.put("echoResponse", new String[] {});
return Collections.unmodifiableMap(result);
MapcreateMap()
create Map
return createMap(INITIAL_CAPACITY);