• 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

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: 23780
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic