• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Sorting with two fields

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do Assignment 3.3 where we put the list of name is an ArrayList and then use the Collections class for sorting.
I am able to get the list of name in an ArrayList object and sort the list by first name using the Collections class, but I am having difficulty figuring out how to sort the list by last name since the instructions say that we have to sort without modifying the strings or the ArrayList.
From what I understand, an Array list is like a single dimensional array. If both fields (first name and last name) are in the same dimension, I don't see how the list can be sorted by anything other than the first field without modifying the strings or the ArrayList. I'm stuck.
 
Trailboss
Posts: 24112
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a good, long look at Collections.sort().
Pulling this off will require that you make a second class.
 
Daniel Olson
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I see it now. I hadn't notice that Collections.sort() had more than one way to sort.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic