File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 46356
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: 15083

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
I agree. Here's the link:
subject: Collection sort
jQuery in Action, 3rd edition