Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

sort in a list

Thread view: 
vincent.fayolle@gmail.com - 19 Sep 2005 22:06 GMT
I have list that contains other lists

like :

List1(
{"Vincent","DUBLIN",12}
{"Stephan","MORGAN",36}
{"Jule","STEPHEN",45}
{"Elisabeth","POQUIN",86}
)

How can I make a stuff like : List1.sort(0) to sort by Name or
List1.sort(2) to sort by age

Thanks
Thomas Hawtin - 19 Sep 2005 22:45 GMT
> I have list that contains other lists

> List1(
> {"Vincent","DUBLIN",12}
> {"Stephan","MORGAN",36}
> {"Jule","STEPHEN",45}
> {"Elisabeth","POQUIN",86}
> )

I suggest you don't do that. Instead introduce a class to represent a
person.

> How can I make a stuff like : List1.sort(0) to sort by Name or
> List1.sort(2) to sort by age

You should use the Collections.sort(List,Comparator) method. You will
need to write a java.util.Comparator implementation that compares the
required field.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Alan Krueger - 20 Sep 2005 03:45 GMT
>> I have list that contains other lists
>> List1(
[quoted text clipped - 6 lines]
> I suggest you don't do that. Instead introduce a class to represent a
> person.

Since this looks an awful lot like a homework assignment, it might be
deliberate.  A great way to show why some approach is better is to make
someone do it the hard way first.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.