Get Highest and Lowest Entry in Java NavigableMap Example

Get Highest and Lowest Entry in Java NavigableMap Example


Posted in : Java Posted on : December 8, 2010 at 6:09 PM Comments : [ 0 ]

This Java Example shows how to Get Highest and Lowest Entry in Java NavigableMap object.

Get Highest and Lowest Entry in Java NavigableMap Example

This Java Example shows how to Get Highest and Lowest Entry in Java NavigableMap object. To get an Entry of first and last position of NavigableMap We use Object firstEntry( ) and Object lastEntry( ) method. These method returns a key-value mapping associated with the least key in this map and with the greatest key in this map, or null if the map is empty from NavigableMap object respectively. 

 Example: FirstAndLastEntryNavigableMap.java

package devmanuals.com;

import java.util.*;

public class FirstAndLastEntryNavigableMap{
	public static void main(String[] args) {
		NavigableMap<Integer, String> Nmap = new TreeMap<Integer, String>();
		Nmap.put(2, "two");
		Nmap.put(1, "one");
		Nmap.put(3, "three");
		Nmap.put(6, "six");
		Nmap.put(5, "five");
		System.out.println("The navigable map first entry is : "
				+ Nmap.firstEntry());
		System.out.println("The navigable map last entry is : "
				+ Nmap.lastEntry());

	}
}

Output:

The navigable map first entry is : 1=one

 The navigable map last entry is : 6=six

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics