Created
June 11, 2023 12:18
-
-
Save john-nash-rs/032d187509dccaa245b697d2ac4211da to your computer and use it in GitHub Desktop.
To demo case matching in java : toLowerCase() and equalsIgnoreCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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