String to char in java- str.charat(index)

If you want to display or get any one character from a string, java provides a method .charAt(index) [this returns a character from the specified index], let’s see the implementation

index should be with in the string length range, else will get exception java.lang.StringIndexOutOfBoundsException

Output

String “Welcome” is of length 7, so the index should be from 0 to 6.

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: