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


Guy Bridge
.a{fill-rule:evenodd;}techdegree seal-36
Guy Bridge
Android Development Techdegree Graduate 24,991 Points

Project question: Using a TreeMap to sort like values


I've been stuck on the last project question for the Soccer League Organiser. The requirement states that as an organizer planning teams, I should be able to view a report of a chosen team grouped by height, so that I can determine if teams are fair.

To me this reads as;

Select your team then show all the players on that team grouped by height.


42" Players Player1 Player2

40" players Player 10 Player 11

I know I've probably got to use a TreeMap or Set like interface but just having trouble sorting the data by height. This is what I have so far;

Map<Integer, List<Player>> playerHeights = new TreeMap<>();
        // Now display the players on that team
        for (Player player : mTeams.getTeams().get(teamIndex).getPlayers())
            List<Player> playerList = new ArrayList<>();
            playerHeights.put(player.getHeightInInches(), playerList);

        // Now display the players depending on their height
        for (int i = 0; i < playerHeights.size(); i++)
                System.out.println("Players that are: " + playerHeights.get(i) + "\"" + " tall");
                System.out.println("PLAYER: " + playerHeights.get(i) + " " + playerHeights.get(i));

        } ```