About Question enthuware.ocpjp.ii.v11.2.1477 :

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

Moderator: admin

Post Reply
philippe
Posts: 26
Joined: Sun Jul 16, 2017 4:24 pm
Contact:

About Question enthuware.ocpjp.ii.v11.2.1477 :

Post by philippe »

You have a collection which contains objects of a class X. When the collection is sorted using Collections.sort(collectionOfX);, X's compareTo() method is used. Which of the following statements are correct about this class X?
Regarding the second correct answer:
The mechanism used in this situation allows the Objects of class X to be sorted in only one way (and the reverse of that way).
How can the list be sorted in the reverse way without using a Comparator?

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

Re: About Question enthuware.ocpjp.ii.v11.2.1477 :

Post by admin »

Not using without a Comparator but without using any new logic that is not already embedded in the compareTo.

The option says, "The mechanism used in this situation allows the Objects of class X to be sorted in only one way (and the reverse of that way)." and this is true because you can do this:

Collections.sort(list, Collections.reverseOrder());

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests