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! Building the Model

Challenge 2 confusion...

Hello,

I'm doing challenge 2 for this video, and i'm stuck on what to do from here:

  public Set<String> getAvailableContactMethods() {
    // FIXME: This should return the current contact method names.
    Set<String> avaliableContactMethods = new HashSet<String>();
    return avaliableContactMethods;
  }

I'm not sure how you are suppose to return the current contact method names...if 'methodName' is a 'getContactInfo' parameter.

Thanks!

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Diego - The HashMap class has the keySet() method that returns a set of all the keys. Call that method on mContactMethods and return the result.

Thanks!

Also, just curious, was 'keySet()' covered before?

Kourosh Raeen
Kourosh Raeen
23,733 Points

You're welcome. Yes, keySet() was covered in the Maps video at 05:07.

Ah, okay.

I hope you don't mind, but could you also help me a little with challenge 3? Here is my code so far:

  public String getContactInfo(Set<String> methodName) {
    // FIXME: return the value for the passed in *methodName*
    methodName = new HashSet<String>();
    for (String method : getAvaliableContactMethods()) {

    }
    return methodName;
  }
Kourosh Raeen
Kourosh Raeen
23,733 Points

For part 3 you need to return a single value for the passed in key methodName, so there is no need for a loop or a HashSet. You just need one line of code that uses HashMaps's get() method to return the value associated with the key methodName.

Thanks!