str.indexof(char) – index of char with in string using java

We have seen how to get a particular character from a string by providing the index, the same manner if we want to know the index of a character [or position] with in a string, java provides a method .indexOf(char c), let’s see the implementation

output

In the above example, t occures multiple times in the string, charAt(‘t’) returns the index of 1st occurrence of character with in the string.

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: