• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting a list  RSS feed

 
Mohamed Amri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a list of Student type objects. I want the elements of this list to be sorted according to the Student name.

How should I deal with that ?
Thanks
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a Comparator object which returns differences between names (possibly even divided into first name, last name).
Assuming you aren't supposed to use the Collections class methods, you will have to implements one of the standard searching algorithms, taking your List and the Comparator as parameters. There have been several posts about how to find sorting algorithms this last week; have a search through the beginner's forum.

Probably best to sort the way Collections#sort(java.util.List, java.util.Comparator) does, creating an array and sorting the array.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!