Java Utililty Methods Map Add

List of utility methods to do Map Add

Description

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

Method

voidarrayToMap(Map destMap, Object[]... oaaArray)
Converts the given array or key/value arrays to a map.
for (Object[] oaMapping : oaaArray) {
    destMap.put(oaMapping[0], oaMapping[1]);
MapArrayToMap(Object[] a)
Create a map from an Object array which contains paired entries (key, value, key, value, ....).
Map m = new HashMap();
for (int i = 0; i < a.length; i += 2) {
    m.put(a[i], a[i + 1]);
return m;
HashMaparrayToMap(Object[] array)
Convert an array to a HashMap, where the key and value of each map element is the same as each list element.
return listToMap(Arrays.asList(array));
MaparrayToMap(Object[] array, Object value)
array To Map
if (array == null) {
    return null;
HashMap<Object, Object> map = new HashMap<Object, Object>();
for (Object object : array) {
    map.put(object, value);
return map;
...
MapArrayToMap(T[] list)
Turn a even length Array into a Map.
HashMap<T, T> map = new HashMap();
if (list == null) {
    return map;
if (list.length > 0 && (list.length % 2) == 1) {
    throw new IllegalArgumentException(
            "Array must be even in length, representing a series of Key, Value pairs.");
for (int i = 0; i < list.length; i++) {
    map.put(list[i], list[++i]);
return map;
MaparrayToMap(X[] objs)
array To Map
if (objs.length % 2 == 1)
    throw new IllegalArgumentException("Odd array len");
HashMap<X, X> ret = new HashMap<X, X>();
for (int i = 0; i < objs.length; i += 2) {
    ret.put(objs[i], objs[i + 1]);
return ret;