import java.util.*; public class EntryExample { public static void main(String[] args) { Mapmap = new HashMap<>(); map.put("one", 1); map.put("two", 2); for (Map.Entry entry : map.entrySet()) { System.out.println(entry.getKey() + ": " + entry.getValue()); } } }
import java.util.*; public class EntryExample { public static void main(String[] args) { MapIn this example, we create a TreeMap and add three key-value pairs to it. We then get the first entry in the map using the `firstEntry()` method and print out its key and value using the `getKey()` and `getValue()` methods of the `Map.Entry` class. Package library: java.utilmap = new TreeMap<>(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); Map.Entry firstEntry = map.firstEntry(); System.out.println("First entry: " + firstEntry.getKey() + ", " + firstEntry.getValue()); } }