Java Map Remove remove(Map> map, K key, V value)

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

Description

remove

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
// This source code is available under the terms of the Affero General Public License v3.

import java.util.Collections;
import java.util.Map;
import java.util.Set;

public class Main {
    public static <K, V> boolean remove(Map<K, Set<V>> map, K key, V value) {
        boolean removed = false;

        Set<V> values = map.get(key);
        if (values != null) {
            removed = values.remove(value);

            if (values.isEmpty())
                map.remove(key);/*from www . ja  v  a 2s  .  co m*/
        }

        return removed;
    }

    public static <K, V> Set<V> get(Map<K, Set<V>> map, K key) {
        Set<V> values = map.get(key);
        return values != null ? values : Collections.<V> emptySet();
    }
}

Related

  1. remove(Map map, String key)
  2. remove(Map map, Collection keys)
  3. remove(Map map, K key)
  4. removeAll(final Map target, final Iterable keys, Collection values)
  5. removeAll(Map map, Set keys)