indexOf( ) searches Index value for the first occurrence of a character.
Example- "This is a test statement".indexOf('a') // 'a' is the character to be searched for in the provided text
indexOf( ) searches Index value for the first occurrence of a substring.
Example - "This is a test statement". indexOf("test") // "test" is the substring to be searched for in the provided text
Lets implement this on Eclipse IDE:
1. Create 'indexOfDemo' class under any project as shown below:
3. Observe that the output is displayed in the console as shown below:
Download this project:
Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
Using lastIndexOf( ) method will be explained in the next post