public class MyClass {public static void main(String[] args) {
String str = "harryjerryharryjerryharry";
System.out.println(str.indexOf('e'));
}
}
Output:
6
The method str.indexOf('e') will return the index of letter e of first occurrence in the string
Another example:
public class MyClass {
public static void main(String[] args) {
String str = "harryjerryharryjerryharry";
System.out.println(str.indexOf("yj"));
}
}
Output:
4
String str = "harryjerryharryjerryharry";
System.out.println(str.indexOf('e'));
}
}
Output:
6
The method str.indexOf('e') will return the index of letter e of first occurrence in the string
Another example:
public class MyClass {
public static void main(String[] args) {
String str = "harryjerryharryjerryharry";
System.out.println(str.indexOf("yj"));
}
}
Output:
4
No comments:
Post a Comment
Note: only a member of this blog may post a comment.