File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Ordering Lists of Lists (Table) by more than one column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ordering Lists of Lists (Table) by more than one column" Watch "Ordering Lists of Lists (Table) by more than one column" New topic

Ordering Lists of Lists (Table) by more than one column

Daslan Govender

Joined: Jan 14, 2005
Posts: 19
I have a struture which is an ArrayList of String[]. I wish to sort
the String[0], String[1], etc.

Any Ideas?

Tks in Advance,
Robert Waals

Joined: Dec 22, 2006
Posts: 14
The convenient way would (if your data comes from a database) to do the sorting in the SQL statement.

Otherwise check this site: sorting
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
An arraylist can be sorted by using the method

This wil sort the arraylist of strings in their natural order.

If you want to sort your own objects in JAVA you have to define your own Comparable interface which can sort over different columns because you have to define your own CompareTo method.

If you have different ways of sorting the best way is to define a Comparator so you can do the sorting with different Comparators.

Collections.sort(ArrayToSort, Comparator)

If the data retrieval is from one table of the database you can choose to do a data retrieval with each new sort order. This would be a performance issue if the dataretrieval is complex and you have to go everytime to the database.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
I agree. Here's the link:
subject: Ordering Lists of Lists (Table) by more than one column
It's not a secret anymore!