Java treemap comparator() method example
Example: Java treemap comparator() method example
// Java treemap comparator() method example
import java.util.Comparator;
import java.util.NavigableMap;
import java.util.TreeMap;
public class TreemapComparatorExample
{
public static void main(String[] args)
{
NavigableMap nm = new TreeMap();
// populating tree map
nm.put(101, "apple");
nm.put(102, "banana");
nm.put(103, "apricot");
nm.put(104, "blackberry");
nm.put(105, "avocado");
// printing TreeMap
System.out.println("TreeMap: " + nm);
// using comparator() method
Comparator c = nm.comparator();
// print comparator value
System.out.println("Comparator value: " + c);
}
}