The startsWith() method of the String class checks whether a given string starts with a specified string or not. It returns boolean true if the string matches, otherwise returns false.
The general form of this method declaration is as follows:
Here, str specifies the string being tested.
For example:
returns true as the string starts with Foo.
The other form of the startsWith() method declaration is as follows:
Here, startIndex specifies the starting index of the invoking string at which the search will begin.
For example,
returns true, as the string, ball, starts from the specified index, i.e., 4.
.
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.