Java Utililty Methods Map from Array

List of utility methods to do Map from Array

Description

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

Method

Mapmap(Object... elements)
Create a map from any number of paris of arguments.
if (elements.length % 2 == 1) {
    throw new IllegalArgumentException("map() requires an even number of arguments");
Map m = map();
for (int ix = 0; ix < elements.length;) {
    m.put(elements[ix++], elements[ix++]);
return m;
...
Mapmap(Object... keyvals)
map
if (keyvals == null) {
    return new HashMap<>();
} else if (keyvals.length % 2 != 0) {
    throw new IllegalArgumentException("Map must have an even number of elements");
} else {
    Map<K, V> m = new HashMap<>(keyvals.length / 2);
    for (int i = 0; i < keyvals.length; i += 2) {
        m.put((K) keyvals[i], (V) keyvals[i + 1]);
...
Mapmap(Object... mapValues)
map
Map map = new HashMap();
for (int i = 0; i < mapValues.length; i = i + 2) {
    map.put(mapValues[i], mapValues[i + 1]);
return map;
Mapmap(Object... objects)
map
if (objects.length % 2 != 0) {
    throw new RuntimeException("bad argument list " + objects.length + ": " + Arrays.toString(objects));
HashMap<String, Object> m = new HashMap<>();
for (int i = 0; i < objects.length; i += 2) {
    m.put((String) objects[i], objects[i + 1]);
return m;
...
Mapmap(Object... objects)
map
HashMap map = new HashMap();
Object key = null;
for (final Object object : objects) {
    if (key == null) {
        key = object;
    } else {
        map.put(key, object);
        key = null;
...
Mapmap(Object... objects)
A short-hand method for creating a Map of key/value pairs where keys are String s and values are Object s.
return genericMap(objects);
Mapmap(Object... objs)
map
return toMap(objs);
Mapmap(Object... objs)
map
if (objs.length % 2 != 0) {
    throw new IllegalArgumentException("Input map should contain even count of arguments.");
Map<String, Object> map = new LinkedHashMap<>();
for (int i = 0; i < objs.length; i += 2) {
    map.put((String) objs[i], objs[i + 1]);
return map;
...
Mapmap(Object... oo)
map
Map result = new HashMap();
for (int i = 0; i < oo.length; i += 2)
    result.put(oo[i], oo[i + 1]);
return result;
Mapmap(Object... params)
map
HashMap map = new HashMap();
for (int i = 0; i < params.length; i += 2) {
    map.put(params[i], params[i + 1]);
return map;