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

voidputAbsent(Map dest, Map src)
put Absent
for (Map.Entry<K, V> entry : src.entrySet()) {
    if (!dest.containsKey(entry.getKey())) {
        dest.put(entry.getKey(), entry.getValue());
voidputAll(final Map dst, final Map src)
Put all entries from the source Map into the destination Map, converting keys and values to Strings if needed
final Iterator<Entry<K, V>> iter = src.entrySet().iterator();
while (iter.hasNext()) {
    final Entry<K, V> entry = iter.next();
    dst.put(toString(entry.getKey()), toString(entry.getValue()));
MputAll(M map, Iterable> values)
Folds all the specified values into the supplied map and returns it.
for (Map<? extends K, ? extends V> val : values) {
    map.putAll(val);
return map;
MapputAll(Map original, Map... others)
put All
for (Map other : others) {
    original.putAll(other);
return original;
voidputAll(Map dest, Collection src, V value)
put All
for (K k : src) {
    dest.put(k, value);
voidputAll(Map map, Map otherMap)
Map.putall with non null check on the other map.
if (otherMap != null) {
    map.putAll(otherMap);
MapputAll(Map map, Object... keysAndValues)
put All
int i = 0;
while (i != keysAndValues.length) {
    map.put((K) keysAndValues[i], (V) keysAndValues[i + 1]);
    i += 2;
return map;
MapputAll(Map model, String prefix, Map subModel)
put All
for (Map.Entry<String, R> e : subModel.entrySet()) {
    model.put(prefix + "." + e.getKey(), e.getValue());
return model;
voidputAll(Map map, String prefix, Map values)
put All
for (Map.Entry<String, String> e : values.entrySet()) {
    map.put(prefix + e.getKey(), e.getValue());
voidputAllIfAbsent(final Map target, final Map source)
Puts entries from the source map into the target map, but without overriding any existing entry in target map, i.e.
source.entrySet().stream().filter(entry -> !target.containsKey(entry.getKey()))
        .forEach(entry -> target.put(entry.getKey(), entry.getValue()));