List of utility methods to do Map Add
void | arrayToMap(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]);
|
Map | ArrayToMap(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; |
HashMap | arrayToMap(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));
|
Map,?> | arrayToMap(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; ... |
Map | ArrayToMap(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; |
Map | arrayToMap(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; |