• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to sort different attributes in Vector?

 
Kelly So
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,
I have following data in my vector...
After selecting the data from database, the result show in web page.......
Emp Code, Emp Name, Emp Telephone, Emp Address....etc
If I want the user to select the sorting attribute....
i.e. Click the Emp Code in web page, and the sorting order become Emp Code?
I have different attribute type for the vector.
Thanks for any help!!!

Regards,
Kelly

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can sort a Vector arbitrarily using static methods in the java.util.Collections class (SDK 1.2 and later). Look at the sort method that takes a List and a Comparator. Since Vector implements List, you can plug it right in.
To change the sorting you use a different Comparator customized for your data. Actually you should use an ArrayList instead of Vector.
Bill

------------------
author of:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic