0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
pratik Samantaray
PRO
last week
Pratikcountry asked

What does the charAt() method do in Java?

Abhay Jajodia
Expert
last week
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.