[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Sorting a Vector

Posted on 2004-04-07
4
Medium Priority
?
610 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 500 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 10782122
8-)
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

656 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