Re: Vector Sort
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Mon, 28 Aug 2006 20:27:06 GMT
"Knute Johnson" <nospam@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:KQNHg.55180$C12.19714@xxxxxxxxxxxxxxx
Christopher Smith wrote: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.
Putting the items in the vector into a treeset may cause you to lose duplicate values.
- Oliver
.
- References:
- Vector Sort
- From: Christopher Smith
- Re: Vector Sort
- From: Knute Johnson
- Vector Sort
- Prev by Date: Re: Memory Allocation in Java
- Next by Date: of beans and taglibs...
- Previous by thread: Re: Vector Sort
- Next by thread: Memory Allocation in Java
- Index(es):
Relevant Pages
|
|