• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

How to get sub lists of a list

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm using Arrays.sort(Object[], Comparator) to help sort some of my objects. However, I now have a need to create sublists off of a sorted list
For example I have a list of following objects
Person[] person = new Person[3];
// The Person constructor takes
// LastName, FirstName
person[0] = new Person(Goodyear, Nancy);
person[1] = new Person(Clark,Stanley);
person[2] = new Person(Goodyear, Elvis);
I sort them
Array.sort(person, Person.LastNameComparator);
The list ends up being
Clark, Stanley
Goodyear, Nancy
Goodyear, Elvis
However, what I want the sort interface to return is a an array of sub lists (each sub list has only duplicates in them) as follows
SubList1: Clark, Stanley
SubList1: Goodyear, Nancy
Goodyear, Elvis
Are there any Java APIs or some other techniques available to do this?
Thanks in advance
PJ
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have always used something akin to the following:
 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joel
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic