List of utility methods to do Map Create
Map | createMap(Object... args) Helper function to create maps easier. assert args.length % 2 == 0; Map<Object, Object> result = new HashMap<Object, Object>(); for (int i = 0; i < args.length; i += 2) { result.put(args[i], args[i + 1]); return result; |
Map | createMap(Object... objects) Create Map filled with values. Map<T, X> map = new HashMap<>(); for (int i = 0; i < objects.length; i++) { map.put((T) objects[i], (X) objects[++i]); return map; |
Map | createMap(Object... objects) create Map if (isEmpty(objects)) { return Collections.emptyMap(); if (objects.length % 2 != 0) { throw new IllegalArgumentException("objects should be even"); Map<K, V> map = new HashMap<>(); for (int i = 0; i < objects.length; i++) { ... |
Map | createMap(Object[] keysValues) create Map Map ret = new HashMap(); for (int i = 0; i < keysValues.length; i = i + 2) { ret.put(keysValues[i], keysValues[i + 1]); return ret; |
Map | createMap(String entries) create Map return fillMap(new HashMap<String, String>(), entries); |
Map | createMap(String key, Object value) create Map return createMap(new String[] { key }, new Object[] { value }); |
Map | createMap(String[] list1, String[] list2) Create a map from the two list of strings. final Map<String, String> ret = new HashMap<String, String>(list1.length); for (int i = 0; i < list1.length; i++) { ret.put(list1[i].trim(), list2[i].trim()); return ret; |
Map | createMap(String[] mappings, String sep) Create map from string description. Map<String, String> dict = new HashMap<>(); for (String m : mappings) { String[] parts = m.split(sep, 2); if (parts.length == 1) { dict.put(m, m); } else { dict.put(parts[0], parts[1]); return dict; |
Map | createMap(T... _args) Creates a map from the even-sized parameter array. Map<T, T> map = new HashMap<>(); if (_args != null) { if (_args.length % 2 != 0) { throw new IllegalArgumentException( "Even number of parameters required to create map: " + Arrays.toString(_args)); for (int i = 0; i < _args.length;) { map.put(_args[i], _args[i + 1]); ... |
Map | createMap(U... items) create Map Map<U, U> result = new HashMap<U, U>(); for (U item : items) { result.put(item, item); return result; |