java.lang.StringBuffer indexOf(String str,int fromIndex)

Syntax:

public int indexOf(String str,int fromIndex)

Java Code Example :

This java example source code demonstrates the use of indexOf(String str,int fromIndex) method of StringBuffer class. Initially the code assigns a string “javatutorialhq.com” as initial contents of the string buffer. Then we use the indexof method to get the starting index of string “a”. This method the same as that of indexOf(String str) of the same class, its just that this method has a specified index to start looking for the specified string.

This is very useful to work with substring method of StringBuffer class. On this example we will also learn how to use the indexof method to work with substring.

Sample Output :

Running the above example source code will give the following output

indexOf(String str, int fromIndex) method example

indexOf(String str, int fromIndex) method example

Suggested Reading List :

References :