Java String indexOf(String str) Example
String class indexOf(String str)method example
String class indexOf(String str) method example. This example shows you how to use indexOf(String str) method.This method Returns the index within this string of the first occurrence of the specified substring.
Here is the code:-
/**
* @(#) IndexofString2string.java
*Program that Returns the index within the string of the first occurrence of the specified substring.
* @Version 02-May-2008
* @author Rose India Team
*/
public class IndexofString2string
{
public static void main(String args[])
{
// Declaration of String
String s = "Welcome to Rose india";
//Displaying the given String definrd above
System.out.println(s);
//Returning the index within the string of the first occurrence of the specified substring.
System.out.println("INDEX OF 'Rose' IN THE STRING IS=" + s.indexOf("Rose"));
}
} |
-
|