Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java List.Contains -- Case Insensitive?
New Posts  All Forums:Forum Nav:

Java List.Contains -- Case Insensitive?

post #1 of 3
Thread Starter 
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!
post #2 of 3
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;
}
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #3 of 3
Thread Starter 
Quote:
Originally Posted by rabidgnome229 View Post
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;
}
Thank You very much, sir!
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Java List.Contains -- Case Insensitive?