startsWith() returns True if a string starts with a specified substring.
public static boolean startsWith(String s1, String s2) {
boolean result = s2.startsWith(s1);
return result;
}
Function Call | Return Value | |||
---|---|---|---|---|
startsWith("H", "Hello") | → | |||
startsWith("el", "Hello") | → | |||
startsWith("Hel", "Hello") | → | |||
startsWith("5", "525") | → | |||
startsWith("52", "525") | → | |||
startsWith("25", "525") | → | |||
startsWith("E", "Egg") | → | |||
startsWith("", "World") | → | |||
startsWith(" ", " Hello World") | → | |||
startsWith(" ", "HelloWorld") | → |
Experiment with this code on Gitpod.io