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

Totally Lost on ScrablePlayer Challenge !!

Need some help with the 'For Each loop' implementation in this challenge.

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;

1 Answer

Hi Shivang,

Let's start by making the getTileCount method signature. Since it's going to return a count, we'll set the return value as an int.

public int getTileCount(char tile) {

We want to return a count of the number of tiles a player has that matches the given tile.

public int getTileCount(char tile) {
  int count = 0;
  // for each letter in mHand
  //    if letter matches tile
  //      increment count
  return count;

If you need a refresher on setting up the for ... each loop, at about 1:08 in the video Current Progress, Craig explains how to do this.

Hope this helps,