aspose file tools*
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
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: 12682
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:

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