logo

Java String IndexOf() Method


Show

Description

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.

Syntax

Here is the syntax of this method:

public int indexOf(char ch)

Parameters

Here is the detail of parameters −

  • ch − a character.

Return Value

  • See the description.

Example

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:

Output

Found Index :4

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.