Page 1 of 1

About Question enthuware.ocpjp.v8.2.1471 :

Posted: Thu Jul 07, 2016 12:37 am
by vitalieb
Hi,
I can't really understand why:
Further, since the subset is created using a range (fromElement to toElement), the element that you are inserting must fall within that range.
Could someone explain ?

Re: About Question enthuware.ocpjp.v8.2.1471 :

Posted: Thu Jul 07, 2016 12:43 am
by admin
This is how the Java standard library designers have designed this class. If the subset accepts an element that doesn't fall within that range, the subset will no more satisfy the condition of that subset. Each element of that subset must be within that range. You should go through the JavaDoc API description of this method.

Re: About Question enthuware.ocpjp.v8.2.1471 :

Posted: Thu Jul 07, 2016 8:54 am
by vitalieb
Thanks

Re: About Question enthuware.ocpjp.v8.2.1471 :

Posted: Fri May 19, 2017 1:23 pm
by lenalena
Is there a reason why the 2 argument subset returns a SortedSet, and the 4 argument subset returns a NavigableSet? (Same applies for both TreeMap.submap() methods, and also for the pair of tailSet/tailMap methods - when the boolean params are included, return is Navigable, otherwise - just Sorted.)

Re: About Question enthuware.ocpjp.v8.2.1471 :

Posted: Fri May 19, 2017 10:09 pm
by admin
Good observation. The hierarchy of sets is like this: Set <- SortedSet <- NavigableSet <- TreeSet. The two parameter subset method is declared in SortedSet, so obviously, it can't return NavigableSet. The four parameter subset method is declared in NavigableSet and it returns the most specific Set type that it can, which is NavigableSet.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1471 :

Posted: Sat May 20, 2017 2:00 pm
by lenalena
Makes sense, thank you.