Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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

Win a copy of The Software Craftsman this week in the Agile forum!
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

Have you tried LearnNowOnline?
subject: Vector sorting