String indexOf example

String indexOf returns the index of the given String for specified conditions. String indexOf method can be used with multiple types of parameters as shown below

1. int indexOf(int ch) returns the index of the first occurrence of the specified character.

2. int indexOf(int ch,int fromIndex) returns the index of the first occurrence of the specified character starting from the “fromIndex”

3. int indexOf(String str) returns the index of the first occurrence of the specified String.

4. int indexOf(String str,int fromIndex) returns the index of the first occurrence of the specified String from the “fromIndex”.

String indexOf 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