> Hi All -
>
> What's the best way to sort a vector of Integers?
>
> Thanks, Chris
Chris:
The simplest way is to remove the elements from the Vector to an array.
The using Arrays.sort(), sort them and put them back into the vector.
You will need to write a Comparator to use with the sort.
Well I just looked at TreeSet and that might actually be simpler. Just
pass your Vector to the TreeSet constructor and they should be sorted
when you retrieve them. I think I like this answer better.

Signature
Knute Johnson
email s/nospam/knute/
Patricia Shanahan - 26 Aug 2006 03:03 GMT
>> Hi All -
>>
[quoted text clipped - 7 lines]
> The using Arrays.sort(), sort them and put them back into the vector.
> You will need to write a Comparator to use with the sort.
Why not just apply Collections.sort to the vector, which does
essentially the same thing with one call?
Also, Integer is Comparable, so a Comparator is needed if, and only if,
the sort is in some special order.
Patricia
Knute Johnson - 26 Aug 2006 03:49 GMT
>>> Hi All -
>>>
[quoted text clipped - 15 lines]
>
> Patricia
Patricia is right that is an even simple solution. Ignore everything I
said :-).

Signature
Knute Johnson
email s/nospam/knute/
Oliver Wong - 28 Aug 2006 21:27 GMT
>> Hi All -
>>
[quoted text clipped - 11 lines]
> pass your Vector to the TreeSet constructor and they should be sorted when
> you retrieve them. I think I like this answer better.
Putting the items in the vector into a treeset may cause you to lose
duplicate values.
- Oliver