This Java Example shows how to Get Highest and Lowest Entry in Java TreeMap object.
Get Highest and Lowest Entry in Java TreeMap Example
This Java Example shows how to Get Highest and Lowest Entry in Java TreeMap
object. To get an Entry of first and last position of TreeMap We use Object
firstEntry( ) and Object lastEntry( ) method. These method returns first
or lowest Entry and last or highest Entry from TreeMap object respectively.
Example: FirstAndLastEntryTreeMap.java
package devmanuals.com; import java.util.*; public class FirstAndLastEntryTreeMap{ public static void main(String args[]) { TreeMap Tmap = new TreeMap(); Tmap.put(1, "Singh"); Tmap.put(3, "Kumar"); Tmap.put(4, "Kumar"); Tmap.put(2, "Nagar"); Tmap.put(6, "Prakash"); System.out.println("The First or lowest Entry is as : " + Tmap.firstEntry()); System.out.println("The Last or Highest Entry is as : " + Tmap.lastEntry()); } }
Output:
The First or lowest Entry is as : 1=Singh
The Last or Highest Entry is as : 6=Prakash |
[ 0 ] Comments