Home » java » Java String Method indexOf()

Java String Method indexOf()

indexOf method is used to get the first occurrence of a sub string in given string. This method takes a string input and return the index value of it in given string object, if sub string not found in string then it returns -1.

Signature

public int indexOf(String str)

Parameters

str is sub string value to find in specified string.

Return

Returns the int value that represents the first occurrence of the sub string in string, if sub string not fount in string then it returns -1.

Example

Result

Managed by MochaHost - Fast & Easy WordPress Hosting