This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to sort the order 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 » Beginning Java
Bookmark "how to sort the order" Watch "how to sort the order" New topic

how to sort the order

devaraj nara

Joined: May 02, 2007
Posts: 2

I have a collection(vector) containing strings.

String is of the format like : 1~bat~34.

eg: 1~qual~34
Now, I want these things in order. It means sub should be first, then qual,then pend, then notqual.
Wanted order is like this : 4~sub~24 then 1~qual~34 then 29~qual~39,then 3~pend~89 then 5~notqual~28. can anyone tell me how to do this.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60774

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

You can use the method sort(List, Comparator) in the class java.util.Collections. The first argument to this method is your Vector, the second is a Comparator object that you have to write which determines the sort order.

Look those classes up in the API documentation and write some code. If you get stuck, please post your code here and explain where you get stuck.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link:
subject: how to sort the order
Similar Threads
using this recursive method slows me down....why?
100 times "hello world" without loop or recursive
Query problem with MySQL 5
Magic Square water retention
Prime numbers