List of utility methods to do Map from Array
Map | map(String k, Object v) map Map<String, Object> map = new HashMap<String, Object>(1); map.put(k, v); return map; |
Map | map(String key, String val) Create a single entry map Map<String, String> map = new HashMap<String, String>(1); map.put(key, val); return map; |
HashMap | map(String... args) map return map((Object[]) args);
|
Map | map(String... args) map if (args == null || args.length == 0) { return Collections.emptyMap(); Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < args.length;) { map.put(args[i++], args[i++]); return map; ... |
Map | map(String... keysAndValues) map if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("Argument count must be even."); Map<String, String> map = new LinkedHashMap<>(); for (int i = 0; i < keysAndValues.length; i += 2) { map.put(keysAndValues[i], keysAndValues[i + 1]); return unmodifiableMap(map); ... |
Map | map(String... keyValues) map HashMap<String, String> map = new HashMap<String, String>(keyValues.length / 2); for (int i = 0; i < keyValues.length;) { map.put(keyValues[i++], keyValues[i++]); return map; |
Map | map(String... strings) Creates a Map out of an array with Strings. if (strings.length % 2 != 0) throw new IllegalArgumentException("strings.length % 2 != 0"); Map<String, String> mp = new HashMap<String, String>(); for (int i = 0; i < strings.length; i += 2) { mp.put(strings[i], strings[i + 1]); return mp; |
Map | map(String... vals) map HashMap<String, String> map = new HashMap<String, String>(); String key = null; for (int i = 0; i < vals.length; i++) { String val = vals[i]; if (key != null) { map.put(key, val); key = null; } else { ... |
Map | map(T... input) Use import static org.couch4j.util.CollectionUtils.set; Map if (null == input || input.length < 1) { return Collections.emptyMap(); if ((input.length & 1) == 1) { throw new IllegalArgumentException( "Input has to contain an even number of arguments: 'key1', 'value1', 'key2', 'values'..."); HashMap<T, T> m = new HashMap<T, T>(); ... |
Map | toMap(Object... args) to Map Map<String, Object> map = new HashMap<String, Object>(); int cntr = 0; String name = null; for (Object o : args) { if (cntr % 2 == 0) { name = (String) o; } else { map.put(name, o); ... |