About Question enthuware.ocpjp.v8.2.1471 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
vitalieb
Posts: 2
Joined: Thu Jul 07, 2016 12:36 am
Contact:

About Question enthuware.ocpjp.v8.2.1471 :

Post 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 ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

vitalieb
Posts: 2
Joined: Thu Jul 07, 2016 12:36 am
Contact:

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

Post by vitalieb »

Thanks

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

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

Post 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.)

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

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

Post by lenalena »

Makes sense, thank you.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 32 guests