The lastIndexOf() method of the String class allows a user to search the last occurrence of a character or a substring from a given string. This method is overloaded in several ways. In all ways, the method returns the index at which the character or the substring was found, or return -1 on failure.
To search for the last occurrence of a character, the following is used:
here, ch specifies the character being searched.
To search for the last occurrence of a substring, the following is used:
To search the occurrence of a character or a substring from a starting index, the following are used:
here, startIndex specifies the point from which the search for a character or a substring begins. The search begins from startIndex to zero.
Get certified in first attempt download scja - SCJA simulation. Download free practice test for SUN SCJA exam.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.
