Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayList & contains() - case insensitive

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

Is there any way?

Thanks


1 Answers

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).

like image 169
Cristian Avatar answered Apr 15 '26 00:04

Cristian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!