Forums Register Login

How to get sub lists of a list

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I have always used something akin to the following:
+Pie Number of slices to send: Send
Thanks Joel
Every plan is a little cooler if you have a blimp. And a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1032 times.
Similar Threads
Sorting list
Sort by Name
Sorting two Classes
Query about compareTo() method
Searching for a list element without having to iterate
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:47:31.