String startsWith example

String startsWith method is used to check if a String starts with a specified substring. Startswith method has 2 variations and we will see both these.

boolean startsWith(String prefix) checks if the String starts with the given prefix.

boolean startsWith(String prefix,int toffset) checks if the sub string of this string beginning at the specified index starts with the specified prefix.

startsWith is case sensitive. Please see the output of the example below.

String startsWith method example



1. String API