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.


public int indexOf(String str)


str is sub string value to find in specified string.


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.



Managed by MochaHost - Fast & Easy WordPress Hosting