aspose file tools*
The moose likes Java in General and the fly likes Make list element case-insensitive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Make list element case-insensitive" Watch "Make list element case-insensitive" New topic
Author

Make list element case-insensitive

satya pksh
Greenhorn

Joined: Jan 17, 2010
Posts: 8
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


satya
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Try looking in the API for String where you will probably find something useful very quickly.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
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.


Joanne
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There's a sort that takes a comparator.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
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

Joined: Oct 13, 2005
Posts: 39834
    
  28
Campbell Ritchie wrote: . . . "ONE" "THREE" "two". . .
Or "ONE" "TWO" "three" depending on the inputs. Please google for ASCIIbetical order, Satya.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make list element case-insensitive