File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Vector sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Vector sorting" Watch "Vector sorting" New topic

Vector sorting

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148

i have a vector that contains the following
a class oblect that contains city name and code.

i need to sort this vector so that the city names are in ascending order

this is how it looks

where N1 = city name
C1 = city code

after sorting


whete N1,C1 part of an object

is there any simple way of sorting

Money for nothing and Java for Free
Craig Tyler
Ranch Hand

Joined: Jan 15, 2006
Posts: 52
Have the class implement Comparable and make the compareTo method sort on the city name. Then, all you have to do is use Collections.sort(). Or, make a Comparator and essentially do the same thing.
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
This is a very good link to understand Comparator and Comparable

I agree. Here's the link:
subject: Vector sorting
It's not a secret anymore!