Java Utililty Methods Map Put

List of utility methods to do Map Put

Description

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

Method

voidputMultiEntry(Map map, Iterable keys, V value)
Convenient method to put several entry in a map having the same value at once.
for (final K key : keys) {
    map.put(key, value);
MapputMultiple(Map map, Object key, Object value)
put Multiple
Object existingValue = map.get(key);
if (existingValue == null)
    map.put(key, value);
else if (existingValue instanceof List)
    ((List) existingValue).add(value);
else
    map.put(key, buildList(existingValue, value));
return map;
...
voidputNotDup(Map tbl, String key, String value)
put Not Dup
if (tbl.containsKey(key)) {
    String v = tbl.get(key);
    if (!contains(v, value)) {
        tbl.put(key, v + "," + value);
} else {
    tbl.put(key, value);
MapputObject(Map map, V key, W value)
put Object
if (map == null) {
    map = new HashMap<T, U>();
map.put(key, value);
return map;
voidputObjectsInMultiMap(Map>> multiMap, Integer key, List stringPair)
Utility function for placing objects in a Map.
if (multiMap == null)
    return;
List<List<String>> tempList = multiMap.get(key);
if (tempList == null) {
    tempList = new ArrayList<List<String>>();
    multiMap.put(key, tempList);
tempList.add(stringPair);
...
voidputOrCreateList(Map> map, K key, V value)
put Or Create List
List<V> list;
list = map.get(key);
if (list == null) {
    list = new ArrayList<>();
    list.add(value);
    map.put(key, list);
} else {
    list.add(value);
...
voidputOrRemove(Map map, String key, Object obj)
put Or Remove
if (obj == null) {
    map.remove(key);
} else {
    map.put(key, obj);
voidputPairs(Map map, Object... pairs)
put Pairs
for (int i = 1; i < pairs.length; i += 2)
    map.put((K) pairs[i - 1], (V) pairs[i]);
voidputParameter(String key, String value, Map map)
put Parameter
if (key.startsWith("$P{")) {
    Object obj = value;
    if (value.startsWith("[") && value.endsWith("]")) {
        String[] array = value.substring(1, value.length() - 1).split(",");
        obj = array;
    map.put(key.substring(3, key.length() - 1), obj);
voidputPreferenceStoredMapValue(String keyOfPreference, String keyInMap, Object value)
Put value with key keyInMapinto the map whose key is keyOfPreference
Map map = getPreferenceStoredMap(keyOfPreference);
map.put(keyInMap, value);
setPreferenceStoredMap(keyOfPreference, map);