TreeMap lastEntry() Method in Java with Examples Last Updated : 02 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.util.TreeMap.lastEntry() method is used to returns the key-value mapping associated with the greatest key in this map, or null if the map is empty. Syntax: tree_map.lastEntry() Parameters: The method does not take any parameters. Return Value: The method returns an entry with the greatest key, or null if this map is empty. Below examples illustrates the working of java.util.TreeMap.lastEntry() method: Example 1: When the map is not empty. Java // Java program to illustrate // TreeMap lastEntry() method import java.util.*; class GFG { public static void main(String args[]) { // Creating an empty TreeMap TreeMap<Integer, String> tree_map = new TreeMap<Integer, String>(); // Mapping string values to int keys tree_map.put(98, "Geeks"); tree_map.put(100, "For"); tree_map.put(103, "Geeks"); // Printing last entry of the map System.out.println("The last entry is : " + tree_map.lastEntry()); } } OutputThe last entry is : 103=Geeks Example 2: When the map is empty. Java // Java program to illustrate // TreeMap lastEntry() method import java.util.*; class GFG { public static void main(String args[]) { // Creating an empty TreeMap TreeMap<Integer, String> tree_map = new TreeMap<Integer, String>(); // Printing last entry of the map System.out.println("The last entry is : " + tree_map.lastEntry()); } } OutputThe last entry is : null Comment More infoAdvertise with us Next Article TreeMap subMap() Method in Java with Examples A abhishekr0ut Follow Improve Article Tags : Java Java-Collections java-TreeMap Practice Tags : JavaJava-Collections Similar Reads TreeMap lowerEntry() method in Java with Examples The lowerEntry() method of java.util.TreeMap class is used to return a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such keySyntax: public Map.Entry lowerEntry(K key) Parameters: This method takes the key as a parameter for which the low 2 min read TreeMap keySet() Method in Java with Examples In Java, keySet() method of TreeMap class is present inside java.util package in Java is used to create a set out of the key elements contained in the treemap. It basically returns a set view of the keys or we can create a new set and store the key elements in them in ascending order. Since the set 3 min read Stack lastElement() method in Java with Example The Java.util.Stack.lastElement() method in Java is used to retrieve or fetch the last element of the Stack. It returns the element present at the last index of the Stack. Syntax: Stack.lastElement() Parameters: The method does not take any parameter. Return Value: The method returns the last elemen 2 min read TreeMap lowerKey() in Java with Examples Pre-requisite: TreeMap in Java The lowerKey() method is used to return the greatest key strictly less than to given key, passed as the parameter. In simpler words, this method is used to find the next greatest element after the element passed as the parameter. Syntax: public K TreeMap.lowerKey(K key 2 min read TreeMap subMap() Method in Java with Examples In Java, subMap() method of TreeMap class is used to return the part or portion of the map defined by the specified range of keys in the parameter. Any changes made in one or the other map will reflect the change in the other map. Syntax: Tree_Map.subMap(K startKey, K endKey) Parameters: The method 3 min read TreeMap values() Method in Java with Examples In Java, the values() method of the TreeMap class is present inside java.util package which is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the TreeMap. --> java.util package --> TreeMap class --> values() Method Syntax: T 2 min read Like