wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes chap 7 doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "chap 7 doubt" Watch "chap 7 doubt" New topic
Author

chap 7 doubt

mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
The Arrays.sort()
methods that sort primitives always sort based on natural order.

Don't be fooled by
an exam question that tries to sort a primitive array using a Comparator.


I am not able to understand above line in KB book page 256
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Originally posted by mukki pandey:
The Arrays.sort()
methods that sort primitives always sort based on natural order.

Don't be fooled by
an exam question that tries to sort a primitive array using a Comparator.


I am not able to understand above line in KB book page 256


That does mean that implementation of Arrays.sort() method does natural
sorting of primitives.

While using Comparator you can achieve other ways of sorting like reverse
order as well. For that you need to implement compare() method of Comparator.

Don't get fooled means, see the implementation of Comparator's method before
coming to conclusion what exactly is happening inside the method, or say
what kinda sorting is implemented inside. Do not come to result that the
sorting is natural order only.



cmbhatt
 
Consider Paul's rocket mass heater.
 
subject: chap 7 doubt
 
Similar Threads
How to accept Multiline conditional input through console in java program....
how the the same operation with "pipe"...
data loss upon 'post'
collections.sort compiler error?
Rumsfeld wins Harold Laski Memorial Fellowship