NavigableMap firstEntry() method in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The firstEntry() method of NavigableMap interface in Java is used to return a key-value mapping associated with the least key in this map, or null if the map is empty. Syntax: Map.Entry< K, V > firstEntry() Where, K is the type of key maintained by this map and V is the type of values mapped to the keys. Parameters: It does not accepts any parameter. Return Value: It returns a key-value mapping associated with the least key in this map, or null if the map is empty. Below programs illustrate the firstEntry() method in Java: Program 1: When the key is integer. Java // Java code to demonstrate the working of // firstEntry() method import java.io.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the NavigableMap of Integer and String NavigableMap<Integer, String> nmmp = new TreeMap<>(); // assigning the values in the NavigableMap // using put() nmmp.put(2, "two"); nmmp.put(7, "seven"); nmmp.put(3, "three"); System.out.println("The mapping with least key is : " + nmmp.firstEntry()); } } Output: The mapping with least key is : 2=two Program 2: When the key is string. Java // Java code to demonstrate the working of // firstEntry() method import java.io.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the NavigableMap of Integer and String NavigableMap<String, String> tmmp = new TreeMap<>(); // assigning the values in the NavigableMap // using put() tmmp.put("one", "two"); tmmp.put("six", "seven"); tmmp.put("two", "three"); System.out.println("The mapping associated with least key is : " + tmmp.firstEntry()); } } Output: The mapping associated with least key is : one=two Reference: https://docs.oracle.com/javase/10/docs/api/java/util/NavigableMap.html#firstEntry() Comment More infoAdvertise with us B barykrg Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions +1 More Practice Tags : JavaJava-CollectionsMisc Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial15+ min readSynchronization in Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like