• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

arrange in ascending order

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
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() );
}
Thanks!
Panday
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Panday
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

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Panday Manako
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave!
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Collections.sort( ListOfNames , String.CASE_INSENSITIVE_ORDER);
------------------
Cindy Glass
Sun Certified Programmer for the Java� 2 Platform
Co-author of Java 2 Certification Passport
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic