Hello Aditya,
According to
Java 6 API, TreeSet implements NavigableSet, which extends SortedSet which exdends Set. The method subSet is defined in SordedSet as
It returns a view of the portion of the set whose elements range from fromElement, inclusive, to toElement, exclusive.
In Java 6, you can also use the subSet method from the NavigableSet, which is defined as:
There you have also the two boolean flags fromInclusive and toInclusive. It returns a view of the portion of the set whose elements are greater than (or equal to, if fromInclusive is true) fromElement and are less than (or equal to, if toInclusive is true) toElement.