Get higherEntry(K key) in Java NavigableMap Example

Get higherEntry(K key) in Java NavigableMap Example


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

This Java Example shows how to Get higherEntry in Java NavigableMap object.

Get higherEntry(K key) in Java NavigableMap Example

This Java Example shows how to Get higherEntry in Java NavigableMap object. To get an higherEntry of NavigableMap We use Map.Entry higherEntry(K key) method. This method returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.

 Example: HigherEntryNavigableMap.java

package devmanuals.com;

import java.util.*;

public class HigherEntryNavigableMap {
	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 higher entry of 4 is : " + Nmap.higherEntry(4));
		System.out
		     .println("The higher entry of 5 is : " + Nmap.higherEntry(5));

	}
}

Output:

The higher entry of 4 is : 5=five 

The higher entry of 5 is : 6=six

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics