![]() |
VOOZH | about |
The comparator() method of java.util.SortedMap interface is used to return the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
Syntax:
public Comparator comparator()
Return Value: This method returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
Below programs illustrate the comparator() method:
Example 1: For Natural ordering.
SortedTreeMap: {1=one, 2=two, 3=three, 4=four, 5=five}
Comparator value: nullExample 2: For Reverse ordering.
SortedTreeMap: {5=five, 4=four, 3=three, 2=two, 1=one}
Comparator value: java.util.Collections$ReverseComparator@232204a1