Solved

Sorting a Vector

Posted on 2004-04-07
4
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

730 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