If I have a TreeSet s, with Integer objects in it, having the following values:
s = [606, 608, 609, 610, 612]
And I run the following code, in a method:
At the end of this, s2 contains: [608, 609, 610]
Now, according to K&B, the booleans in the subset method above indicate whether the endpoint is exclusive. I am unable to understand that bit. Can someone please point out how exactly do the booleans work in the subSet/subMap syntax?
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.