About Question enthuware.ocpjp.v7.2.1294 :
Moderator: admin
- 
				alex
 - Posts: 42
 - Joined: Tue Feb 12, 2013 4:35 pm
 - Contact:
 
About Question enthuware.ocpjp.v7.2.1294 :
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
			
			
									
									
						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: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1294 :
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.
- 
				alex
 - Posts: 42
 - Joined: Tue Feb 12, 2013 4:35 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1294 :
Ohh, see now.
I haven't attach any importance to this.
Thanks,
Alex
			
			
									
									
						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 :
public static List getNameList() 
gives the expected result, but is evaluated as "invalid".
			
			
									
									
						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 :
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
			
			
									
									
						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: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1294 :
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>?
			
			
									
									
						- 
				Leimodnunewra
 - Posts: 5
 - Joined: Mon Aug 25, 2014 5:44 am
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1294 :
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: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1294 :
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.
			
			
									
									
						Note: TestClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
- 
				Leimodnunewra
 - Posts: 5
 - Joined: Mon Aug 25, 2014 5:44 am
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1294 :
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.
			
			
									
									
						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 :
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)
			
			
									
									
						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 :
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.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.
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
Who is online
Users browsing this forum: No registered users and 19 guests