my dog learned polymorphism
The moose likes Beginning Java and the fly likes Sort Multi Dimension array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sort Multi Dimension array" Watch "Sort Multi Dimension array" New topic

Sort Multi Dimension array

sudhir pavan
Ranch Hand

Joined: Sep 01, 2011
Posts: 35
How to sort array list with multi dimension value in java using built in function.


No Name Address

5 sss US
1 www UK
4 yyyy SL
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 187
Create a class representing the objects with the given attributes, something like this:

Create/populate the List with these objects:

Create the comparator for these objects:

Invoke the sort utility:
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46405
Your post is a little confusing. Do you mean to sort an array or a List? Does the List contain objects of your class? I would say the only object‑oriented way to do it is to create objects of some class or other. Then, as an alternative to the Comparator, you can make that object implement the Comparable interface. You can find more about the interfaces mentioned in the Java Tutorials.
I agree. Here's the link:
subject: Sort Multi Dimension array
jQuery in Action, 3rd edition