This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collection sort" Watch "Collection sort" New topic

Collection sort

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635


I read this code in this book:
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

Joined: Oct 13, 2005
Posts: 45292
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

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: 15038

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 8 API documentation
subject: Collection sort
It's not a secret anymore!