File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Vector sorting

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
hi


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
------------------------
N4,C4|N1,C1|N3,C3|N2,C2|
------------------------

where N1 = city name
C1 = city code

after sorting

------------------------
N1,C1|N2,C2|N3,C3|N4,C4|
------------------------

whete N1,C1 part of an object

is there any simple way of sorting


Money for nothing and Java for Free
SCJP, SCWCD
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 http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html


http://www.skillassert.com


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector sorting