Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sorting a vector

 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic