List of utility methods to do Map Create
Map | map(K key, V value, Object... keysValues) Creates the HashMap of Integers Map<K, V> res = new HashMap<>(); res.put(key, value); if (keysValues.length > 0) { if (keysValues.length % 2 > 0) { throw new IllegalArgumentException("Arguments count must be even!"); for (int i = 0; i < keysValues.length; i += 2) { K k = (K) keysValues[i]; ... |
Map | map(K key, V value, Object... moreKeysAndValues) map Map<K, V> map = new HashMap<>(); map.put(key, value); for (int i = 0; i < moreKeysAndValues.length; i += 2) { map.put((K) moreKeysAndValues[i], (V) moreKeysAndValues[i + 1]); return map; |
Map | map(K key0, V value0) Create a map with one key and a corresponding value. return Collections.singletonMap(key0, value0);
|
Map | map(K key1, V value1, Object... objects) Creates a map out of an infinite amount of parameters. Map<K, V> ret = new LinkedHashMap<>(); ret.put(key1, value1); Iterator<Object> iter = Arrays.asList(objects).iterator(); while (iter.hasNext()) { K key = (K) iter.next(); V value = (V) iter.next(); ret.put(key, value); return ret; |
Map | map(K[] keys, V[] values) Creates a mapping from two arrays, one with keys, one with values. if (keys.length != values.length) { throw new IllegalArgumentException("Number of keys and values is different. " + "Cannot create map."); Map<K, V> map = new HashMap<K, V>(); for (int i = 0; i < keys.length; i++) { K key = keys[i]; V value = values[i]; map.put(key, value); ... |
M | map(M map, K key, V value) map map.put(key, value);
return map;
|
Map | map(Map map) map if (map == null) { return null; Map<String, String> result = new HashMap<String, String>(); if (map.isEmpty()) { return result; Set<Entry<String, Object>> entrySet = map.entrySet(); ... |
Object | map(Map map, Object key) map if (map == null) { return null; return map.get(key); |
Map | map(Map.Entry map HashMap<K, V> resultMap = new HashMap<K, V>(entries.length); for (Map.Entry<K, V> mapEntry : entries) { resultMap.put(mapEntry.getKey(), mapEntry.getValue()); return resultMap; |
Map | map(Map.Entry map Map<String, Object> map = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : entries) { map.put(entry.getKey(), entry.getValue()); return map; |