Re: Vector Sort




"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

.



Relevant Pages

  • Re: TreeSet Sorting Question
    ... > Jane Doe ... > The default TreeSet sorting sorts by first name, ... You'd implement the Comparator interface to sort in whatever ...
    (comp.lang.java.help)
  • Re: Is there a PHP command to
    ... > Just wondering what the simplest way to sort IP addresses would be ... Rik Wasmus ... $array = array( ...
    (comp.lang.php)
  • Re: Vector Sort
    ... 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. ... Just pass your Vector to the TreeSet constructor and they should be sorted when you retrieve them. ...
    (comp.lang.java.help)
  • Re: Is numeric keys of Pythons dictionary automatically sorted?
    ... times people have asked this newsgroup how they can sort a dictionary. ... If you want the keys of a dict sorted, get the keys, and sort them ... similar to the TreeSet and TreeMap classes in ...
    (comp.lang.python)
  • Re: Vector Sort
    ... 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. ...
    (comp.lang.java.help)