Java Map Put put(Map map, K key, V value)

Here you can find the source of put(Map map, K key, V value)

Description

Associates the specified value with the specified key in this map.

License

Open Source License

Parameter

Parameter Description
map The map to be operated on.
key Key with which the specified value is to be associated.
value Value to be associated with the specified key.
K The class of keys in this map.
V The class of values in the map.

Declaration

public static <K, V> void put(Map<K, V> map, K key, V value) 

Method Source Code

//package com.java2s;
/*/*from   ww w  .j a v  a  2 s .c om*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import java.util.Map;

public class Main {
    /**
     * Associates the specified value with the specified key in this map. If the map previously contained a mapping for
     * the key, the old value is replaced by the specified value.
     *
     * @param map   The map to be operated on.
     * @param key   Key with which the specified value is to be associated.
     * @param value Value to be associated with the specified key.
     * @param <K>   The class of keys in this map.
     * @param <V>   The class of values in the map.
     */
    public static <K, V> void put(Map<K, V> map, K key, V value) {
        if (map != null) {
            map.put(key, value);
        }
    }
}

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 aMap, K aKey, V aValue)
  5. put(Map map, K key, V value)
  6. put(Map map, String key, Object value)
  7. put(Map structure, String name, Object object)
  8. put(ThreadLocal> threadLocal, Object key, String value)