The .contains() method returns True if the specified substring is found in a string.
public static boolean hasIt(String s1, String s2) {
boolean result = s2.contains(s1);
return result;
}
Function Call | Return Value | |||
---|---|---|---|---|
hasIt("e", "Hello") | → | |||
hasIt("g", "Hello") | → | |||
hasIt("2", "525") | → | |||
hasIt("74", "525") | → | |||
hasIt("gg", "Egg") | → | |||
hasIt("", "World") | → | |||
hasIt(" ", "Hello World") | → | |||
hasIt(" ", "HelloWorld") | → |
Experiment with this code on Gitpod.io