Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection sort  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 53733
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 15860
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API documentation of the Collections.sort(List, Comparator) method and of java.util.Comparator.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!