This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sort Multi Dimension array" Watch "Sort Multi Dimension array" New topic
Author

Sort Multi Dimension array

sudhir pavan
Ranch Hand

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

Ex:

No Name Address

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

Joined: Mar 24, 2005
Posts: 186
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
Sheriff

Joined: Oct 13, 2005
Posts: 38100
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sort Multi Dimension array
 
Similar Threads
reassigning new references to previously defined array variables
Sorting multi dimensional array
Array
Array
Sorting multi-dimension arrays