• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection sort  RSS feed

 
S Majumder
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
 
William Brogden
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
 
Rob Spoor
Sheriff
Posts: 21135
87
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!