• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arrange in ascending order

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dave!
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic