|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Java List.Contains -- Case Insensitive?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Programmer
|
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! |
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Kernel Sanders
|
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:
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;
}
|
|||||||||||||
|
|
|
|
#3 (permalink) | |
|
Programmer
|
Quote:
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|