To check if a
String
has a character in Java, do this: string.indexOf(char) >= 0
.Here's how you do it:
String string = "Hello World!";
boolean hasH = string.indexOf('H') >= 0;
boolean hasSpace = string.indexOf(' ') >= 0;
boolean hasZ = string.indexOf('Z') >= 0;
System.out.println(hasH); // true
System.out.println(hasSpace); // true
System.out.println(hasZ); // false