TreeSet
puts an element in natural ordering or by the provided
comparator.SortedSet
is also keeps the element in natural orderBut what is the difference between them and NavigableSet?
Where are NavigableSets
useful?
Some example to show its usage would be nice for beginners.
SortedSet is an interface (it defines the functionality) and Treeset is an implementation. NavigableSet is also an interface subtype of the SortedSet.
You can't just write SortedSet<Integer> example = new SortedSet<Integer>();
You can however write SortedSet<Integer> example = new TreeSet<Integer>();
As its name implies, NavigableSets are more useful for navigating through the set.
http://mrbool.com/overview-on-navigableset-subtype-of-java-collections/25417 offers a good tutorial on NavigableSets and some of the methods available when using one, that aren't available in a SortedSet.