Java Map Remove remove(Map map, K key)

Here you can find the source of remove(Map map, K key)

Description

Removes the mapping for a key from this map if it is present.

License

Open Source License

Parameter

Parameter Description
map The map to be operated on.
key The key whose mapping is to be removed from the map.
K The class of keys in this map.
V The class of values in the map.

Return

The previous value associated with key, or null if there was no mapping for key.

Declaration

public static <K, V> V remove(Map<K, V> map, K key) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w . j ava  2 s  .  co m*/
 * 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 {
    /**
     * Removes the mapping for a key from this map if it is present.
     *
     * @param map   The map to be operated on.
     * @param key   The key whose mapping is to be removed from the map.
     * @param <K>   The class of keys in this map.
     * @param <V>   The class of values in the map.
     * @return      The previous value associated with key, or null if there was no mapping for key.
     */
    public static <K, V> V remove(Map<K, V> map, K key) {
        if (map == null)
            return null;
        return map.remove(key);
    }
}

Related

  1. remove(Map map, String key)
  2. remove(Map> map, K key, V value)
  3. remove(Map map, Collection keys)
  4. removeAll(final Map target, final Iterable keys, Collection values)
  5. removeAll(Map map, Set keys)
  6. removeAllFromCollection(Map> map, Object key, Collection values)
  7. removeAllNullValueEntry(Map source)