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

Sorting vectors

 
John Brookes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a vector (LimitSet) of "Limit" objects, a limit consisting of an integer (pos) and a double (speed). How would I (if I even can) use Collections.sort to order the contents of the LimitSet by "pos"?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the version of sort() that takes a java.util.Comparator as an argument. Provide a Comparator implementation which compares two Limit objects by subtracting their "pos" members and returning the result.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could either modify the definition of LimitSet to implement Comparable or create a Comparator to use to call Collections.sort
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic