This method revisits the index inside this string of the initial incidence of the specified substring. If it does not happen as a substring, -1 is returned.
Here is the syntax of this method:
int indexOf(String str)
Here is the detail of parameters −
import java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to Intellinuts.com"); String SubStr1 = new String("Tutorials"); System.out.println("Found Index :" + Str.indexOf( SubStr1 )); } }
This will produce the following result:
Found Index :11
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.