how to check substring is present in string in java code example
Example 1: how to check if a string contains a character
public static boolean containsIgnoreCase(String str, char c) {
str = str.toLowerCase();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == Character.toLowerCase(c)) {
return true;
}
}
return false;
}
Example 2: string check if substring exists java
String str1 = "Java";
String str2 = "va";
if(str1.contains(str2)){
// str1.contains(str2) will be true here.
System.out.println("I am true");
}