This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Collection sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collection sort" Watch "Collection sort" New topic
Author

Collection sort

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635


30
12
7
7
-5


I read this code in this book:
SCJP
Sun Certified Programmer
for Java® Platform, SE6
Study Guide
I can't understand how Reverse method work, so How these numbers are sorted?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
What Reverse method? There isn't a Reverse() method anywhere. You are creating a Reverse object. What can you not see about its workings? You have got the whole class there in front of you Go through it with a pencil and paper and see how it works.
Brian Enochson
Greenhorn

Joined: Apr 12, 2011
Posts: 14

Also, try changing the compare method by switching the o1 and o2 around in the return statement. That should give you a clue of what is happening.

Like this:


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Read the API documentation of the Collections.sort(List, Comparator) method and of java.util.Comparator.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Collection sort