Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

String sorting

Thread view: 
DBC User - 09 Oct 2006 14:35 GMT
Hi I am newbie to Java. I am using an arraylist to collect string line
input from gui. So my array list is list of strings. I want to sort it.
What is the best way to sort this in ascending order?
Thanks
solaimadhan@gmail.com - 09 Oct 2006 14:54 GMT
check out Arrays.sort()

> Hi I am newbie to Java. I am using an arraylist to collect string line
> input from gui. So my array list is list of strings. I want to sort it.
> What is the best way to sort this in ascending order?
> Thanks
opalpa opalpa@gmail.com http://opalpa.info - 09 Oct 2006 16:17 GMT
Arrays.sort() for arrays.  Collections.sort() for collections.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort(java.uti
l.List
)

opalpa
opalpa@gmail.com
http://opalpa.info/
DBC User - 10 Oct 2006 14:25 GMT
Thanks both Arrays.sort is what I was looking for. But I still have an
issue with the order in which it sorts.

I have following input

Aa bB Cc
aa bb cc
Aa Bb Cc
Aa bb Cc
Aa bb cc
bb cc aa

and I get the following output

aa bb cc
bb cc aa
Aa bb cc
Aa bb Cc
Aa bB Cc
Aa Bb Cc

But I would like to get
aa bb cc and then
Aa bb Cc

Is there a way to do this in the sort?
'Thanks.

> Arrays.sort() for arrays.  Collections.sort() for collections.
>
[quoted text clipped - 3 lines]
> opalpa@gmail.com
> http://opalpa.info/
Patricia Shanahan - 10 Oct 2006 14:51 GMT
> Thanks both Arrays.sort is what I was looking for. But I still have an
> issue with the order in which it sorts.
[quoted text clipped - 22 lines]
>
> Is there a way to do this in the sort?

Supply a Comparator that implements the ordering you want.

Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.