The indexOf() technique returns the location of the initial incidence of a specific character(s) in a string. Utilize the lastIndexOf method to revisit the place of the last rate of a specified character(s) in a string.
Here is the syntax of this method:
public int indexOf(char ch)
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"); System.out.print("Found Index :" ); System.out.println(Str.indexOf( 'o' )); } }
This will produce the following result:
Found Index :4
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.