|
This is a simple String class IndexOf method example, in which method returns index location or number position of the specified character for a word or sequence of charaters, method returns the index location of letter with which the word starts.
public class StringIndex {
public static void main(String args[]){
String str = "jsp servlet tutorial";
int str1= str.indexOf('h'),
str;
System.out.println("Index of 'j' in String 'str' is: " + str1);
System.out.println("Index of 's' in String 'str' is: " + str.indexOf("s"));
System.out.println("Index of 'servlet' in String 'str' is: " + str.indexOf("
servlet"));
}
}
|
|