Page 1 of 1

About Question enthuware.ocpjp.v7.2.1294 :

Posted: Mon Mar 25, 2013 10:48 am
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

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

Posted: Mon Mar 25, 2013 11:05 am
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.

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

Posted: Mon Mar 25, 2013 11:36 am
by alex
Ohh, see now.
I haven't attach any importance to this.

Thanks,
Alex

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

Posted: Fri Jul 19, 2013 9:43 am
by arthoor
public static List getNameList() 

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

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

Posted: Tue Aug 26, 2014 4:37 am
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

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

Posted: Tue Aug 26, 2014 5:59 am
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>?

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

Posted: Tue Aug 26, 2014 6:07 am
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.

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

Posted: Tue Aug 26, 2014 9:58 am
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.

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

Posted: Wed Aug 27, 2014 2:44 am
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.

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

Posted: Tue Dec 22, 2015 4:38 am
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)

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

Posted: Wed Jun 22, 2016 8:01 am
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