Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Sorting a Vector of "User" Objects

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Servlet that after a quick haul through my database, set's up a Vector of "Users". Each "User" had about 10 attributes that are set via a javabean.
One of these Attributes is of type double, and I need to sort the entire list of "Users" based on this double variable in each, from highest to lowest.
So right now to get that value, I use "u1.getTbws()", which returns me a double value for 1 particular user.
How can I get this value for each user ( about 40 users on an average ), and sort them from Highest to lowest ? (sort the entire Vector for display purposes in my JSP)
Any help/suggestions/examples would be tremendously helpful.
Thanks,
java@nbnet.nb.ca
[ April 06, 2004: Message edited by: David Donovan ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can solve ur problem using
java.util.Collections.sort()
& java.util.Comparator interfaces..
Regards,
Jelda
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try

[ April 07, 2004: Message edited by: J�rg Vater ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or go all the way and implement your own sorted List which automatically sorts items as you insert them.
Then all you need is use that instead of any other List and implement Comparable in your other classes.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic