Newbie arraylist question
This is a stupid newbie question!
I have 2 arraylists which are linked. One arraylist contains values 1-30 and the other contains a short "memo".
how do i go about displaying all of them in the terminal window so that when a number is selected from arraylist 1 the corresponding value is selected from arraylist2.
Can i sort arraylist1 into ascending order so that when the values are displayedit would be like...1, 2, ...
Thank you for your time
It sounds like data structure wise, you probably don't need/want two ArrayLists here. There are always a few different options when it comes to how you set up your data structures so I'll suggest one or two.
I'm guessing you are storing the 1-30 values as Integer classes since ArrayList takes objects. You could use a single java.util.HashMap instead since it holds key/value pairs. Your HashMap's key is your 1-30, and the HashMap's value is the "memo" (assuming a String). Once you have your HashMap initialized, getting the correpsonding value to the user-chosen 1-30, let's say 10, is as easy is
Now, I'm assuming the 1-30 is not just an index, that it has some meaning and the order is not necessarily always guaranteed to be 1,2,3 etc... If it's really just an index, then you should be able to use a single ArrayList and let the Lists's index serve as the 1-30. So you could create a new ArrayList of size 30
and use that. If they choose 10, access the value with
myArrayList = new ArrayList(30)
I used 10-1 because your index will be from 0-29 and you're presenting the user with 1-30.
Hope that makes some sense? Let me know if I'm way off and I'll try again.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center