This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting

 
Santhan Rajah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic