• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
Rancher
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: 21424
94
Chrome Eclipse IDE Java 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!