logo

Java String IndexOf(String Str) Method


Show

Description

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.

Syntax

Here is the syntax of this method:

int indexOf(String str)

Parameters

Here is the detail of parameters −

  • str − a string.

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");
      String SubStr1 = new String("Tutorials");
      System.out.println("Found Index :" + Str.indexOf( SubStr1 ));
   }
}

This will produce the following result:

Output

Found Index :11

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