String indexOf(int ch int fromIndex) method Java

Let’s learn String indexOf(int ch, int fromIndex) method java.

String indexOf(int ch, int fromIndex) method Java

String indexOf(int ch, int fromIndex) method returns the index within this string of the first occurrence of the specified character, starting the search at the specified index or -1 if the character does not occur.

Syntax:

public int lastIndexOf(int ch, int fromIndex)

Parameters:

ch a character (Unicode code point).

fromIndex the index to start the search from.

Example:

class StringIndexOfMethodDemo 
{
    public static void main(String[] args) 
    {
        String s = new String("Hello World Java");
        System.out.println("Index found at : " + s.indexOf('J', 5));
    }
}

Output:

Index found at : 12

Also read – Abstraction in java