# Java List.Contains -- Case Insensitive?



## Lyoko

Is there a way to use List.Contains(var) in case-insensitive form? E.g. if the list had "LyokoHaCk" and I plugged in "lyokohack" for the variable, it would still return true.

I've tried iterating this and converting it to a string array then looping, but no luck!

Thanks for the help!


----------



## rabidgnome229

Here's a method to do what you want. A quick browse of the API didn't turn up any way to do it without writing some code of your own.

Code:



Code:


public boolean containsIgnoreCase(List <String> l, String s){
 Iterator <String> it = l.iterator();
 while(it.hasNext()){
  if(it.next().equalsIgnoreCase(s))
  return true;
 }
 return false;
}


----------



## Lyoko

Quote:


Originally Posted by *rabidgnome229* 
Here's a method to do what you want. A quick browse of the API didn't turn up any way to do it without writing some code of your own.

Code:



Code:


public boolean containsIgnoreCase(List <String> l, String s){
 Iterator <String> it = l.iterator();
 while(it.hasNext()){
  if(it.next().equalsIgnoreCase(s))
  return true;
 }
 return false;
}


Thank You very much, sir!


----------

