Example usage for java.util Map remove

List of usage examples for java.util Map remove

Introduction

In this page you can find the example usage for java.util Map remove.

Prototype

default boolean remove(Object key, Object value) 

Source Link

Document

Removes the entry for the specified key only if it is currently mapped to the specified value.

Usage

From source file:Main.java

public static void main(String[] args) {
    Map<Integer, String> map = new HashMap<>();

    for (int i = 0; i < 10; i++) {
        map.putIfAbsent(i, "val" + i);
    }//w  w w .  j  a v a  2s . c o  m

    map.forEach((id, val) -> System.out.println(val));

    map.remove(3, "val3");
    System.out.println(map.get(3)); // val33

    map.remove(3, "val33");
    System.out.println(map.get(3)); // null
}