This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Make list element case-insensitive

 
satya pksh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my java application i need to compare two list's element whether it is similar or not.

In short suppose i have two list declared like shown below


If i write a condition for equality it fails as some of list's element is in different case like


It will display result "Not equal"

So please tell me how i can make the list element case-insensitive in java language only.

Thank and regard
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try looking in the API for String where you will probably find something useful very quickly.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Try looking in the API for String where you will probably find something useful very quickly.


I assume you are referring to String.equalsIgnoreCase(). That was my first thought as well until I re-read the OP. a and a1 are Arraylists containing Strings, not Strings. Sorry if I'm wrong about your assumption, but I couldn't see anything in the String API that would help here.

My second thought was to check the Collections class to see if it had an equals or compare method that took a Comparator as a parameter, but I couldn't see anything. Maybe satya could write such a method.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a sort that takes a comparator.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant both equalsIgnoreCase and the built-in Comparator in the String class, Joanne; you need that Comparator, otherwise it will sort "ONE" "THREE" "two". As you say, you would have to write your own method using it equalsIgnoreCase.

And yes, just like you, I thought it meant comparing the Strings. Sorry.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote: . . . "ONE" "THREE" "two". . .
Or "ONE" "TWO" "three" depending on the inputs. Please google for ASCIIbetical order, Satya.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic