Java Utililty Methods Map Create

List of utility methods to do Map Create

Description

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

Method

Mapmap(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];
...
Mapmap(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;
Mapmap(K key0, V value0)
Create a map with one key and a corresponding value.
return Collections.singletonMap(key0, value0);
Mapmap(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;
Mapmap(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);
...
Mmap(M map, K key, V value)
map
map.put(key, value);
return map;
Mapmap(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();
...
Objectmap(Map map, Object key)
map
if (map == null) {
    return null;
return map.get(key);
Mapmap(Map.Entry... entries)
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;
Mapmap(Map.Entry... entries)
map
Map<String, Object> map = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : entries) {
    map.put(entry.getKey(), entry.getValue());
return map;