In this video, indexOf(), lastIndexOf() and substring methods are explained with the help of two programs in the Java environment.
Link to the Book - Essentials of Computer Applications:
https://www.amazon.in/Essentials-Comp...
Lesson 62: practice Exercise - indexOf()
1. Initialize a string to "This is a book is". Read a character and display all index positions at which the character is present.
T h i s i s a b o o k i s
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Output:
Enter a character to search: i
2
5
15
2. Initialize a string to "Java is Java". Read a string and display all index positions at which the String is present.
J a v a i s J a v a
0 1 2 3 4 5 6 7 8 9 10 11
Output:
Enter a String to search: Java
0
8