This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes sorting a vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "sorting a vector" Watch "sorting a vector" New topic

sorting a vector

Deyna Cegielski
Ranch Hand

Joined: Nov 24, 2004
Posts: 60
is there anyways to sort a vector into ascending/descending order?
im trying to do this for a vector of dates.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
A java.util.Vector is a java.util.List, and there are sort methods for Lists in java.util.Collections. Dates are java.lang.Comparable, so "by default" they will be sorted in increasing order, but Collections also has a sort that let lets you supply a java.util.Comparator to determine the ordering. Finally, to reverse the "natural" Comparable ordering, see Collections' reverseOrder method, or use Collection's reverse method to reverse the list itself.

There is no emoticon for what I am feeling!
I agree. Here's the link:
subject: sorting a vector
It's not a secret anymore!