Java SE API
Map.keySet()
Inspect keys and, where supported, remove mappings through the view. Adding keys alone is unsupported.
Formal Syntax & Structure
java syntaxjava
Set<K> keySet()Return Value
Set<K>
Backed key view.
Working Example
Example Snippetjava
import java.util.*;public class Main {
public static void main(String[] args) { Map<String, List<String>> groups = new LinkedHashMap<>(); groups.computeIfAbsent("desk", key -> new ArrayList<>()).add("pen"); groups.computeIfAbsent("shelf", key -> new ArrayList<>()).add("book"); groups.computeIfAbsent("desk", key -> new ArrayList<>()).add("pad"); System.out.println(groups); Iterator<String> keys = groups.keySet().iterator(); while (keys.hasNext()) { if (keys.next().equals("shelf")) keys.remove(); } System.out.println(groups); }}