Java Map Put put(Map aMap, K aKey, V aValue)

Here you can find the source of put(Map aMap, K aKey, V aValue)

Description

Adds given key and value to given map (removes key if value is null).

License

Open Source License

Declaration

public static <K, V> V put(Map<K, V> aMap, K aKey, V aValue) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    /**//from  ww  w.  j  a v a  2s.  c o  m
     * Adds given key and value to given map (removes key if value is null).
     */
    public static <K, V> V put(Map<K, V> aMap, K aKey, V aValue) {
        if (aValue == null)
            return aMap.remove(aKey);
        return aMap.put(aKey, aValue);
    }
}

Related

  1. put(Map map, Object key, int value)
  2. put(Map map, String k1, Object v1, String k2, Object v2)
  3. put(Map map, String keyValuePair)
  4. put(Map map, K key, V value)
  5. put(Map map, K key, V value)
  6. put(Map map, String key, Object value)
  7. put(Map structure, String name, Object object)