Java SE API
Map.entrySet()
Traverse key-value pairs. Mutation support depends on the map; supported removal from the view removes the mapping.
Formal Syntax & Structure
java syntaxjava
Set<Map.Entry<K,V>> entrySet()Return Value
Set<Map.Entry<K,V>>
Backed view of mappings.
Working Example
Example Snippetjava
import java.util.*;public class Main {
public static void main(String[] args) { Map<String, Integer> counts = new TreeMap<>(); for (String word : List.of("pear", "apple", "pear", "plum")) { counts.merge(word, 1, (oldValue, added) -> oldValue + added); } for (Map.Entry<String, Integer> entry : counts.entrySet()) { System.out.println(entry.getKey() + ": " + entry.getValue()); } }}