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
2 comments:
Going through these different types of String Handling methods and one question is rotating in my mind.
In real time, when do we need these ?
Understanding the purpose of the methods through this blog but having real time scenarios will help beginners like me, so we can relate.
Post a Comment