How to sort an arraylist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have an arraylist that contains integer values. What i want to ask you all is how i would retrieve the index values when the values have been sorted. For example..
lets assume the index values are in brackets and the values contained in it is shown immeditaly preceding it.

Arraylist1
(0)4 , (1)2, (2)1, (3)2, (4)0, (5)

i want the arraylist to now be sorted according to the values contained in it (smallest integer first). However i want the index values maintained. i.

(4)0, (2)1, (1)2, (3)2, (5)3, (0)

I then want the Index values retrieved in the order above
i.e i want this order of index's retrieved.
(4), (2), (1), (3), (5), (0

Can anyone tell me if this is possible?
ANy help would really be appreciated

thankU
 
Y, if you want to be able to retrieve the original indexes, I'd can the
Arraylist and use a hashtable. Store the original index as your key and the
integer (4, 2, 1, 2, 0, 3 ) as your values. You can find either one if you
know it's counterpart.

HTH,

Bill
Y said:
Hi I have an arraylist that contains integer values. What i want to ask
you all is how i would retrieve the index values when the values have been
sorted. For example...
lets assume the index values are in brackets and the values contained in
it is shown immeditaly preceding it..
Arraylist1.
(0)4 , (1)2, (2)1, (3)2, (4)0, (5)3

i want the arraylist to now be sorted according to the values contained in
it (smallest integer first). However i want the index values maintained. i.e
 
Hi william

do u have an example of how to use a hashtable

The reason i need to retrieve the origional indexes is beacause i have a second arraylist whose values correspond directly to the arraylist that needs to be sorted
I need to input the indexes retrieved from the sorted arraylist and use them to retrieve the values ffom the second arraylist
 
Back
Top