• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Collection sort  RSS feed

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every body I have a small problem in sorting .

I am taking one collection of type string .When I am sorting I is giving me wrong result.

Here is my code :


It is sorting like :
Alpha
Beta
Delta
alpha1
theta.


Here I can take ant type of string even upper case / lower case .
But the lower case words are coming later .

I want the out put like :

Alpha
alpha1
Beta
Delta
theta



Please help me out.

thanks ,
S
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String comparisons pay attention to upper and lower case - an 'a' does not follow 'A' immediately in UNICODE.

The String class has the method compareToIgnoreCase() - you can use that to make a Comparator which will do what you want.

Bill
 
Sheriff
Posts: 21466
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Brogden wrote:The String class has the method compareToIgnoreCase() - you can use that to make a Comparator which will do what you want.


Or simply use the already existing String.CASE_INSENSITIVE_ORDER comparator.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much , I have solved the problem.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!