indexOf() - String Methods in Java
This article is a part of
String Methods in Java.
The indexOf() method returns the index within the string of the first occurrence of the specified character. The parameter passed in this method can be of String type which represents the string to be searched, or of char type representing a character to be searched. We can pass one more parameter fromIndex which indicates the index from where the search should begin.
The return type of indexOf() method is an int value. The integer represents the first
occurrence of the specified parameter, if the output is -1 then it represents that the
specified parameter never occurs.
Let us look at an example for this method.
Let us look at the output of the above.