Solved

Sorting a Vector

Posted on 2004-04-07
4
600 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
allStar challenge 1 43
What is the latest versions eclipse neon 2 122
JDeveloper 12c for 32 bit 4 35
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now