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 Maps Java Maps Java Maps Quiz

Rob Siepkowski
Rob Siepkowski
7,641 Points

Java "get" method on a Map. Question from Quiz

/*** This is a quiz question. It is asking us to fill in blank below to retrieve Ravi's grade. I have tried a dozen different variations of studentGradeMap.get() with random spellings and variations of ravi and student and quotes and parens and everything I can think of and nothing is working. please help!! Thank you! ***/

Fill in the blank to retrieve Ravi's Grade from the Map:

import java.util.HashMap; import java.util.Map;

public class Main {

public static void main(String[] args) {
    Student ravi = new Student();
    Student sid = new Student();
    Student grace = new Student();
    Grade A = new Grade();
    Grade B = new Grade();
    Grade C = new Grade();
    Grade D = new Grade();

    Map<Student, Grade> studentGradeMap = new HashMap<>();
    studentGradeMap.put(ravi, B);
    studentGradeMap.put(sid, C);
    studentGradeMap.put(grace, B);

    Grade ravisGrade = // ????? fill in blank here ??????
}

}

class Student { // omitted }

class Grade { // omitted }

4 Answers

Have you tried

studentGradeMap.get(ravi)

?

Rob Siepkowski
Rob Siepkowski
7,641 Points

Thanks Kris! Much appreciated!!

I thought I had already tried that.

I had tried the exact same thing you wrote, but I was putting ravi in quotes ... "ravi". That's where i was going wrong.

Your answer works perfectly!

Thanks so much!

Hi there.I was facing the same issue but you already asked the same question thank you so much.

studentGradeMap.get(ravi)

Map <Student,Grade> studentGradeMap = new HashMap<>();