PRO
Pratik
asked

Expert
Abhay Jajodia answered
Hello Pratik, really nice question.
charAt() is a method in Java that lets you grab a single character from a string. You just give it the position you want, and it hands you back the character at that spot.
Java starts counting from zero, so:
the first character is at index 0
the second is at index 1
and so on
For example:
String text = "Hello";
char c = text.charAt(1); // 'e'
If you try an index that doesnât exist, Java throws an error because the string doesn't go that far.
Youâll use charAt() a lot when you loop through a string and check each character, like when counting vowels.
If you have further questions, I'm here to help.
Java
This question was asked as part of the Java Interview Questions course.







