public class IndexOfMethod { public void useIndexOfMethod() { String str = "This is bharat singh"; char c = 'i'; System.out.println("String : " + str); String searchString = "is"; // Display the index of given character System.out.println("First occurrence of character " + c + " : " + (str.indexOf(c))); // Display the first occurrence of a character from specified index System.out.println("First occurrence of character " + c + " search start at specified index 4 = " + (str.indexOf(c, 4))); // Display the first occurrence of a string System.out.println("First Index of string " + searchString + " : " + (str.indexOf(searchString))); // Display the first occurrence of a string from specified index System.out.println("First occurrence of string : " + searchString + " : search start at specified index 3 = " + (str.indexOf(c, 3))); } public static void main(String[] args) { IndexOfMethod obIndexOfMethod = new IndexOfMethod(); obIndexOfMethod.useIndexOfMethod(); } }