wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "sorting a vector" Watch "sorting a vector" New topic
Author

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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sorting a vector
 
Similar Threads
Vector with bean:write tag
Vector V/s ArrayList
declaring a new Vector
"has a"
get the result set in to the vector