File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes multidimensional array sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multidimensional array sort" Watch "multidimensional array sort" New topic

multidimensional array sort

Lacey Anderson

Joined: Apr 13, 2004
Posts: 2
Please help. I am very new to java and trying to build a multidimensional array. I have two variables 1)item_name and 2)item_value. These are values that I obtain by looping through a database result set. I need to build and array that can hold these variables. Once the multidimensional array is built I need to be able to sort it by item value.
For example I would like to do something like this:
while ( = item_name
array.value = item_value

Thanks for any help!
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
It might be worth considering making a very simple Item object that implements Comparable. All you'll need is getters and setters for the 'value' and 'name' properties and a compareTo method. you can use Arrays.sort() or Collections.sort() depending on what structure you store the Items in.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
For an easy introduction to working with (multi-dimensional) arrays in Java, let me suggest Bradley Kjell's Introduction to Computer Science using Java. Chapters 46-49 cover the topics.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Lacey Anderson

Joined: Apr 13, 2004
Posts: 2
Thanks for the link. The book is a great resource. I actually ended up using a tree map and a compareTo method in my object definition. It worked great.
Thanks for the responses!
I agree. Here's the link:
subject: multidimensional array sort
It's not a secret anymore!