1import java.util.TreeMap;
2public class TreeMapPollFirstEntryMethodExample
3{
4 public static void main(String[] args)
5 {
6 TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
7 tm.put(63, "yellow");
8 tm.put(95, "red");
9 tm.put(96, "green");
10 tm.put(21, "violet");
11 tm.put(28, "blue");
12 System.out.println("TreeMap before using pollFirstEntry() method: " + tm);
13 System.out.println("Value is: " + tm.pollFirstEntry());
14 System.out.println("TreeMap after using pollFirstEntry() method: " + tm);
15 }
16}
1import java.util.TreeMap;
2public class TreeMapPollLastEntryMethodExample
3{
4 public static void main(String[] args)
5 {
6 TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
7 tm.put(63, "yellow");
8 tm.put(95, "red");
9 tm.put(96, "green");
10 tm.put(21, "violet");
11 tm.put(28, "blue");
12 System.out.println("TreeMap before using pollLastEntry() method: " + tm);
13 System.out.println("Value is: " + tm.pollLastEntry());
14 System.out.println("TreeMap after using pollLastEntry() method: " + tm);
15 }
16}