The list of methods to do Map Add are organized into topic(s).
void
addOne(Map map, K key) Increment a Map of K->Integer for a given key.
if (map != null) {
if (map.get(key) != null) {
map.put(key, map.get(key) + 1);
} else {
map.put(key, 1l);
void
addOne(Map map, T key) given a map of ?
Integer count = map.get(key);
if (count == null)
count = 0;
map.put(key, count + 1);
Map
> addTo(Map> map, K key, T value)
Add a value to a map containing a list of values mapped to a key.
List<T> tl = map.get(key);
tl.add(value);
map.put(key, tl);
return map;
List
addToList(Map> map, X key, Y value)
add To List
List<Y> values;
if (map.containsKey(key)) {
values = map.get(key);
values.add(value);
} else {
values = new ArrayList<Y>();
values.add(value);
map.put(key, values);
...
void
addToListMap(Map map, Object key, Object value) Add a value to a Map from keys to Set of values, creating the value list as needed.
if (map == null) {
throw new IllegalArgumentException("invalid map");
if (key == null) {
throw new IllegalArgumentException("invalid map key");
List valuesList = (List) map.get(key);
if (valuesList == null) {
...
boolean
addToListMap(Map> map, K key, V value) Populated a (key,value) pair in a map of lists.
if (map == null) {
return false;
List<V> list = map.get(key);
if (list == null) {
list = new ArrayList<V>();
map.put(key, list);
if (!list.contains(value)) {
list.add(value);
return true;
return false;
void
addToListMap(Map> map, String key, String value) Adds another element to the Map: The list of strings is enlarged
List<String> currentList;
if (map.containsKey(key)) {
currentList = map.get(key);
} else {
currentList = new ArrayList<String>();
currentList.add(value);
map.put(key, currentList);
...
Map
> addToListMap(Map> map, T key, T value)
add To List Map
if (map == null)
return null;
if (key == null || value == null)
return map;
List<T> set = map.get(key);
if (set == null)
set = new ArrayList<T>();
set.add(value);
...