comparator treemap code example
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<Integer, String> nm = new TreeMap<Integer, String>();
nm.put(101, "apple");
nm.put(102, "banana");
nm.put(103, "apricot");
nm.put(104, "blackberry");
nm.put(105, "avocado");
System.out.println("TreeMap: " + nm);
Comparator c = nm.comparator();
System.out.println("Comparator value: " + c);
}
}