String lastIndexOf example

String lastIndexOf returns the index of the last occurrence of the given String for specified conditions searching backward. String lastIndexOf method can be used with multiple types of parameters as shown below

1. int lastIndexOf(int ch) returns the index of the last occurrence of the specified character searching backward.

2. int lastIndexOf(int ch,int fromIndex) returns the index of the last occurrence of the specified character starting from the “fromIndex” searching backward

3. int lastIndexOf(String str) returns the index of the last occurrence of the specified String searching backward.

4. int lastIndexOf(String str,int fromIndex) returns the index of the last occurrence of the specified String from the “fromIndex” searching backward.

String lastIndexOf example

Output

Please Note:
Before performing any operation on any dynamically generated String, check if the String is not null.
Else a NullPointerException is thrown.

Reference

1. String API

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn