views:

228

answers:

1

Hi!

I want the contains() method from ArrayList to be case insensitive.

Is there any way?

Thanks

+6  A: 

No. You will have to define your own contains method that will have to iterate among the ArrayList and compare the values using the equalsIgnoreCase method of the String class.

Edit: I don't want to be rude, but the question is pretty clear: the guy wants to use the contains method. So he can't/should use toLowerCase before adding the elements because of too many reasons: for example, he could need the original String (not the one that is lowercased). Also, as we are talking about the contains method, we are focusing on the elements rather than their indexes (as someone answered some minutes ago).

Cristian
hey! no problem! thank you everyone for the quick answers!
Philipz