About Question enthuware.ocpjp.v7.2.1294 :

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

Moderator: admin

Post Reply
alex
Posts: 42
Joined: Tue Feb 12, 2013 4:35 pm
Contact:

About Question enthuware.ocpjp.v7.2.1294 :

Post by alex »

Hi,

The question in this issue is incorrect.
I can't get list in order [amy, Adam, audrey] via the proposed options.

[amy, audrey, Adam] - original list
[Adam, amy, audrey] - standart sorting
[audrey, amy, Adam] - reverse soring. The correct answer suggest this option, but it is not [amy, Adam, audrey]

Please check

Regards,
Alex

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

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by admin »

Did you run the code exactly as given? There is a space in front of " audrey". The explanation also mentions the following:
In case of String elements, the natural order is: space < upper case < lower case. Here, the output is expected to be in reverse order, therefore, we need a reverse order Comparator. Collections.reverseOrder() returns such a comparator.
If you like our products and services, please help us by posting your review here.

alex
Posts: 42
Joined: Tue Feb 12, 2013 4:35 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by alex »

Ohh, see now.
I haven't attach any importance to this.

Thanks,
Alex

arthoor
Posts: 3
Joined: Thu Jul 04, 2013 11:19 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by arthoor »

public static List getNameList() 

gives the expected result, but is evaluated as "invalid".

Leimodnunewra
Posts: 5
Joined: Mon Aug 25, 2014 5:44 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by Leimodnunewra »

Hey there,

I was just wondering why List<String> is the only accepted answer for the first part when List will return the same output? Is it to do with type erasure?

Thanks,

Leimodnunewra

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

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by admin »

Because in the main method the return value is being assigned directly (without any cast) to List<String>. Did you try the code with just List instead of List<String>?
If you like our products and services, please help us by posting your review here.

Leimodnunewra
Posts: 5
Joined: Mon Aug 25, 2014 5:44 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by Leimodnunewra »

Yes, I did. I got the same result that I had gotten when using List<String> which is why I am curious about the given answer.

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

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by admin »

I get the following warning if I don't use List<String>:
Note: TestClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
If you like our products and services, please help us by posting your review here.

Leimodnunewra
Posts: 5
Joined: Mon Aug 25, 2014 5:44 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by Leimodnunewra »

I don't get any warnings at all, it runs as if I had used List<String>, that's strange. Thank you for your help though.

Edit:
I had to clean and build the project to get the warnings to show up, I will try this in future.

Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by Sergiy Romankov »

There is some missleading in the explanation:

3. Collections.sort(collection) method sorts the elements of the given collection in the natural order of it elements.

Method Collections.sort takes argument of type List<T> but not a collection
So should be:
Collections.sort(List<T> list)

dieterdde
Posts: 19
Joined: Wed May 25, 2016 4:33 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1294 :

Post by dieterdde »

admin wrote:Did you run the code exactly as given? There is a space in front of " audrey". The explanation also mentions the following:
In case of String elements, the natural order is: space < upper case < lower case. Here, the output is expected to be in reverse order, therefore, we need a reverse order Comparator. Collections.reverseOrder() returns such a comparator.
OH MY LORD!!! Pffffffff, I could NOT for the life of me figure out this thing, as I knew that none of the code would return the right order, following the rules of natural sorting.

Did NOT see the extra space in front of audrey............

I had 30 minutes left to spare in the test, and spent it almost entirely on this 1 question... should have just finished the test and checked the answer!!!

Well played Paul, well played!

Cheers,
Dieter

Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests