When you need to find where a character or substring appears, use .indexOf(). It returns the index of the first occurrence, or if the target is not found.
String msg = "Java is fun";
int pos = msg.indexOf("is");
System.out.println(pos);
This prints because the substring "is" starts at index . If you just need to know whether a substring exists without caring about position, use .contains() instead. It returns a boolean.
boolean found = msg.contains("fun");
System.out.println(found);
This prints true. Under the hood, .contains() calls .indexOf() and checks if the result is not . Both methods are case-sensitive. "java" will not match "Java". If you need case-insensitive searching, convert both strings to the same case first with .toLowerCase().