Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Delivering the MVP Using Method Overloading

charAt?

I know that I'm probably giving this question too late. I understand that charAt shows the location of a char in a String, but why exactly do we need to know that for our code?

1 Answer

Hi Dinu. The charAt(int i) method actually returns the letter in a String at a given index i. In the video and that Hangman exercise, we need to call charAt(0) because of the Scanner.

A Scanner in Java does not parse char. So we have to use a String, and then call charAt(0) on that String to get its first and only letter.

I hope this helps :)