File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to sort different attributes in 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 » Servlets
Bookmark "How to sort different attributes in Vector?" Watch "How to sort different attributes in Vector?" New topic

How to sort different attributes in Vector?

Kelly So

Joined: Mar 27, 2001
Posts: 20
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!!!


William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12759
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.

author of:
I agree. Here's the link:
subject: How to sort different attributes in Vector?
Similar Threads
writing a class object in session variable in jsp
vector sorting
object sorting in a Vector
sorting table columns
How to search a Vector array?