This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collections.sort() on Array List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Collections.sort() on Array List" Watch "Collections.sort() on Array List" New topic
Author

Collections.sort() on Array List

Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
Hello,

Below is code I created based on Sierra/Bates Chapter 7. It compiles and runs; I have a related question. See below.



This following is output:

[2001 sci-fi ??
, Caddy Shack comedy Murray, Bill
, Donnie Darko sci-fi Gyllenhall, Jake
, Lost in Translation comedy Murray, Bill
, Patriot Games action Ford, Harrison
, Raiders of the Lost Ark action Ford, Harrison
, Star Wars sci-fi Ford, Harrison
]



Is there another way this code can compare dvdList without having DVDInfo extend Comparable? Sierra/Bates mentions:

Returning to our earlier example for class DVDInfo, we can take the easy way out and use the String class’s implementation of compareTo():



Please clarify what is the un-easy way to compare dvdList?


Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Take a look at java.util.Comparator
Alpesh Padra
Ranch Hand

Joined: Jan 10, 2010
Posts: 41
You can implement sorting by 2 way

1. Comparable
2. Comparator with compare(T o1, T o2) method


Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Is this you want? Check and reply....


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Abimaran Kugathasan
Please don't provide any code.


kunal
 
jQuery in Action, 2nd edition
 
subject: Collections.sort() on Array List
 
Similar Threads
compareTo
Putting an object instance into an ArrayList
Putting an object instance into an ArrayList
Sorting Collections
Collections and array Problem