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 (Retired) Creating the MVP For Each Loop

Alex Rodriguez
Alex Rodriguez
Front End Web Development Techdegree Student 20,810 Points

How do u get getTileCount to accept char?

I have been trying to solve this challenge, I thought the method was accepting char since it was declared in for ( char tile: mHand.toCharArray()) Otherwise what is that doing?

public class ScrabblePlayer {
  private String mHand;

  public ScrabblePlayer() {
    mHand = "";

  public String getHand() {
   return mHand;

  public void addTile(char tile) {
    // Adds the tile to the hand of the player
    mHand += tile;

  public boolean hasTile(char tile) {
   return mHand.indexOf(tile) > -1;

  public String getTileCount() {
   String counter = "";
    for ( char tile: mHand.toCharArray()){
      char display = '-';
      if (mHand.indexOf(tile) >= 0 ) {
       display = tile;
     counter += tile; 

    return counter;

1 Answer

Rob Bridges
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Alex,

I think I just answered the earlier question about this, but what the for loop is doing is looping through each character in your mHand.toCharArray(), which basically, it is breaking apart each letter or character in the string and then running the code in the loop beneath it.


I'm not sure if this is what you were meaning with your question, but to make getTileCount accept a character as an argument, we'd pass that as a parameter into it.

getTileCount(char letter)

Or something similar.