The moose likes Beginning Java and the fly likes arrange in ascending 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 "arrange in ascending order" Watch "arrange in ascending order" New topic

arrange in ascending order

Panday Manako
Ranch Hand

Joined: Mar 29, 2001
Posts: 80
How can you arrange words in ascending order ignoring the case?
I always get an order in which words that start with an uppercase letter are on top.
example: Z,a,b,c,E
result: E,Z,a,b,c
here's my partial code
Collections.sort( ListOfNames );
Iterator firstName = ListOfNames.iterator();
while ( firstName.hasNext() )
System.out.println( firstName.next() );
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
What you need to do is sort the Strings ignoring case. If your going to use the sort method then you might want to use the overloaded form that takes a list and a comparator. The comparator lets you define your own comparison criteria the sort method then uses that to sort your list.
Your comparator would look something like this:

This is an adaptation of an old utility class I had made and used inner classes to facilitate this.
Then in your code just send the sort method your lsit and the comparator.
hope that helped

Sun Certified Programmer for the Java� 2 Platform

Panday Manako
Ranch Hand

Joined: Mar 29, 2001
Posts: 80
Thanks Dave!
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Collections.sort( ListOfNames , String.CASE_INSENSITIVE_ORDER);
Cindy Glass
Sun Certified Programmer for the Java� 2 Platform
Co-author of Java 2 Certification Passport

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link: http://aspose.com/file-tools
subject: arrange in ascending order
Similar Threads
Regarding sorting of a list object
pls help me.
poll() and peek()
Nobel price, medicine
Is the answer correct?