lastIndexOf( ) method searches Index value for the last occurrence of a character or a substring.
"This is a test statement of a person".lastindexOf('a') -> searches index value for the last occurrence of character 'a'.
"This is a test statement of a test person".lastindexOf("test") -> searches index value for the last occurrence of substring "test"
Lets implement this on Eclipse IDE:
1. Create 'lastIndexOfDemo' class under any project as shown below:
3. Observe that the output is displayed in the console as shown below:
Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
Using 'substring( )' method will be explained in the next post.