O. Ziggy wrote:
I looked at the API and it is saying that TreeSet.headSet returns a NavigableSet<E> which has just confused me even more.
NavigableSet is an interface that is implemented by the TreeSet class. A TreeSet IS-A NavigableSet. A NavigableSet is not necessarally a TreeSet. So... it may be a good idea to use NavigableSet instead, as the headSet() method may not always return an object that may be casted to TreeSet, in future implementations.
Henry