• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on sorting with Collections class

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on the SortNames assignment and can sort the names by the first name but am stuck trying to sort by the last name of the ArrayList.
Does anyone have any hints?
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I maintain that the key to getting the sort by last names to work is first understanding why the sort by first names works.
(By *understanding* I mean, roughly, that you don't need to understand the gory details of the underlying sort algorithms Collections uses, but that you should gain some appreciation of how Java seems to "know" that you want the original list of Strings sorted in alphabetical order. Take a good look at the Collections class, especially the various sorting methods.)
If you search this forum, you should find several good threads on this assignment and sorting in general. But I'd recommend first taking another shot at figuring it all out on your own.
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe a little more help:
'sort' may have more then one parameter!
Look in the API for sort!
 
Gerald Dettling
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. After figuring out how to setup the other class I got it to work!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic