Java String indexOf(int ch, int fromIndex) Example
String class indexOf(int ch, int fromIndex)method example
String class indexOf(int ch, int fromIndex)method example. This example shows you how to use indexOf(int ch, int fromIndex) method.This method Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
Here is the code:-
/**
* @(#) IndexofString1.java
*Program that Returns the index within the given string of the first occurrence of the specified character, starting the search at the specified index.
* @Version 02-May-2008
* @author Rose India Team
*/
class IndexofString1
{
public static void main(String[] args)
{
// Declaration of String
String a="Welcome to Rose india";
//Displaying the given String definrd above
System.out.println("Given string is:-"+a);
//Returns the index of a substring('o') in this StringBuffer starting with index 4.
System.out.println("INDEX OF 'O' IN THE STRING IS="+a.indexOf('o',4));
}
} |
-
|