TreeMap pollFirstEntry() method in java code example
Example 1: TreeMap pollFirstEntry() method in java
import java.util.TreeMap;
public class TreeMapPollFirstEntryMethodExample
{
public static void main(String[] args)
{
TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
tm.put(63, "yellow");
tm.put(95, "red");
tm.put(96, "green");
tm.put(21, "violet");
tm.put(28, "blue");
System.out.println("TreeMap before using pollFirstEntry() method: " + tm);
System.out.println("Value is: " + tm.pollFirstEntry());
System.out.println("TreeMap after using pollFirstEntry() method: " + tm);
}
}
Example 2: TreeMap pollLastEntry() method in java
import java.util.TreeMap;
public class TreeMapPollLastEntryMethodExample
{
public static void main(String[] args)
{
TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
tm.put(63, "yellow");
tm.put(95, "red");
tm.put(96, "green");
tm.put(21, "violet");
tm.put(28, "blue");
System.out.println("TreeMap before using pollLastEntry() method: " + tm);
System.out.println("Value is: " + tm.pollLastEntry());
System.out.println("TreeMap after using pollLastEntry() method: " + tm);
}
}