How to determine if a Java contains a certain character?
In Java, you can use the contains() method of the String class to check if a string contains a certain character. For example:
String str = "Hello World";
char ch = 'o';
if (str.contains(String.valueOf(ch))) {
System.out.println("字符串包含字符'" + ch + "'");
} else {
System.out.println("字符串不包含字符'" + ch + "'");
}
The code above will output “String contains character ‘o'” because the string “Hello World” contains the character ‘o’. To check if a string contains multiple characters, you can use the contains() method multiple times for each character.