Java String indexOf() Method The indexOf() method returns the position of the first occurrence of specified character(s) in a string . Tip: Use the lastIndexOf method to return the position of the last occurrence of specified character(s) in a string.