• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multidimensional array sort

 
Lacey Anderson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 (rs.next)
array.name = item_name
array.value = item_value
end
array.sort(value)

Thanks for any help!
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
-Tim
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lacey Anderson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic