Why is subSet
method specified in SortedSet
Interface instead of Set unlike subList
method of List
interface?
A subSet
operation requires the underlying Set
to have ordering. Otherwise there's no meaning to request all the elements from element X to element Y.
The base Set
interface doesn't require ordering (for example, HashSet
s are not ordered). Therefore it can't support this operation.
The List
interface is ordered, so having subList()
method there makes sense.