How to sort an arraylist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Y

    #1

    How to sort an arraylist

    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
  • William Ryan  eMVP

    #2
    Re: How to sort an arraylist

    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" <anonymous@disc ussions.microso ft.com> wrote in message
    news:E24D3C94-A36C-409E-A701-E24BEE5649F9@mi crosoft.com...[color=blue]
    > Hi I have an arraylist that contains integer values. What i want to ask[/color]
    you all is how i would retrieve the index values when the values have been
    sorted. For example...[color=blue]
    > lets assume the index values are in brackets and the values contained in[/color]
    it is shown immeditaly preceding it..[color=blue]
    >
    > 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[/color]
    it (smallest integer first). However i want the index values maintained. i.e[color=blue]
    >
    > (4)0, (2)1, (1)2, (3)2, (5)3, (0)4
    >
    > 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[/color]


    Comment

    Working...