Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

alphabetizing lists

 
Mario Bonassin
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea how to do this one. I need a simple code that will take a listModel and alphabetize the items. I would like it if it could do it with the first letter and last letter, seperatly of course.
Any suggestions or advise would be great.
Mario
 
sever oon
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll want to use java.util.Comparator and java.lang.Comparable. You can write a comparator to sort a java Collection in any way you see fit. You can also use the Comparator to instantiate sorted collections so you don't have to sort things all at once, they get inserted into their sorted positions at the time of insertion. Or, many classes already implement the Comparable interface so they have a "natural ordering". Strings have this capability already...

sev
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic