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 Data Structures - Retired Efficiency! Using a Map to store Contact Methods

I really did not understand why the answer for the last question is return mContactMethods.get(methodName);

How com ethe answer the last one is: return mContactMethods.get(methodName);

and just a regular setter with

return mContactMethods?

1 Answer

michaelcodes
michaelcodes
5,604 Points

Hi there! So for this challenge the information is being stored in a HashMap. This means that the information is paired up in a {key, content} type relationship. In this challenge it is {method, value}.

So in the last part of the challenge the method is supposed to return only the contact information. We use mContactMethods.get(methodName) because this will search in our Map for whatever the contact method is, and return the associated information. (Say the variable methodName was "email", it would be finding the associated email address)

If we only returned mContactMethods we would be returning the full array, rather than 1 specific value.

Hope this helps!