Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Sorting 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 » Java » Beginning Java
Bookmark "Sorting" Watch "Sorting" New topic
Author

Sorting

Santhan Rajah
Greenhorn

Joined: Mar 26, 2003
Posts: 3
Hi!
I have a ArrayList like this:
ArrayList cds = new ArrayList();
and cds is an object from one another class named as CD.
This cds-object contains strings.
And now I want to sort these strings alphabetically, can I anyone help me pls?

You help is appreciated.

/Santhan
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

if you have overridden the compareTo, equals and hashCode methods in the class your adding to the list, then you can just call
Collections.sort( yourList );
otherwise you need to create a comparator object and use the
Collections.sort( yourList, yourComparator )
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting
 
Similar Threads
how to fill a combobox with values from objects in an ArrayList...
jsf data table
multidimensional array
ArrayList
Yoga