Solved

Sorting a Vector

Posted on 2004-04-07
4
604 Views
Last Modified: 2010-03-31
I have a Vector of objects that I want to sort.

The only way I figured how to do this is to :
1) Convert the Vector to an Array, using vector.toArray()
2) Sort the array, using Arrays.sort()
3) Fill the Vector back with the sorted array, using a loop !

Quite tricky...

Is there any simpler way??

Thanks,
stsanz.
0
Comment
Question by:stsanz
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 10775829
Collections.sort(yourVecotr);
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10775883
Keep in mind though that  Collections.sort() sort according to the elements 'natural' order, which might or might not suit your needs! If you need a different, or custom sorting order for your elements you have to implement the Comparator interface and provide an instance with the call to Collections.sort(). Find more infor about Compartor at http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html .
0
 

Expert Comment

by:RobCSP
ID: 10775984
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10782122
8-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question