Wednesday, May 18, 2011

SortedSet interface methods in java

The SortedSet interface is used by TreeSet and adds additional methods to reflect that a TreeSet is sorted.
SortedSet sset;

Result Method Description
comp = sset.comparator() Returns Comparator used to compare elements. null if natural ordering used (eg, String).
obj = sset.firstKey() First element (in sorted order).
obj = sset.lastKey() Last element (in sorted order).
sset = sset.headMap(obj) Returns SortedSet of all elements less than obj.
sset = sset.tailMap(obj) Returns SortedSet of all elements greater than or equal to obj.
sset = sset.subMap(from, to) Returns SortedSet of all elements greater than or equal to from and less than to.

No comments:

Post a Comment

Chitika