pollFirstEntry(): This method is available in java.util.TreeMap class of Java.
Syntax:
Entry<K, V> java.util.TreeMap.pollFirstEntry()
This method removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.
Parameters: NA
Returns: the removed first entry of this map,or null if this map is empty.
Exceptions: NA
Approach
Java
import java.util.TreeMap;public class TreeMappollFirstEntry {public static void main(String[] args) {TreeMap<Integer, String> treeMap =new TreeMap<Integer, String>();treeMap.put(2, "Hello");treeMap.put(11, "Java");treeMap.put(23, "Program");treeMap.put(6, "C++");treeMap.put(25, "Program");System.out.println(treeMap.pollFirstEntry());}}
Output:
2=Hello
No comments:
Post a Comment