Skip to content

Instantly share code, notes, and snippets.

@john-nash-rs
Created June 11, 2023 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-nash-rs/032d187509dccaa245b697d2ac4211da to your computer and use it in GitHub Desktop.
Save john-nash-rs/032d187509dccaa245b697d2ac4211da to your computer and use it in GitHub Desktop.
To demo case matching in java : toLowerCase() and equalsIgnoreCase
import java.util.ArrayList;
import java.util.List;
public class StringDemo {
public static void main(String[] args) {
System.out.println("** Demo of String Functions **");
List<String> demoList = new ArrayList<>();
demoList.add("Bread");
demoList.add("Jam");
demoList.add("Egg");
demoList.add("Milk");
String key = "bread";
for(String item : demoList){
if(item.toLowerCase().equals(key.toLowerCase())){
System.out.println(" Item found in list "+key);
}
}
for(String item : demoList){
if(item.equalsIgnoreCase(key)){
System.out.println(" Item found in list "+key);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment