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

Android Build a Blog Reader Android App Adapting Data for Display in a List Adding Secondary Data with a SimpleAdapter

Challenge task 1 of 4 HashMap

Question: Inside the onCreate() method, create two HashMap<String, String> variables and in each one, store a website name value using KEY_NAME as the key and the website URL value using KEY_URL as the key.

There are already two variables created: public static final String KEY_NAME = "name"; public static final String KEY_URL = "url";

I thought they where asking for this: HashMap<String, String> webStie = new HashMap<String, String>(); webStie .put(KEY_NAME, name); webStie .put(KEY_URL, url);

I have searched the internet which gives me a completely different way to write the code.

1 Answer

You got it right, partly though. The question asks you create two HashMaps of String-String type. In both of them you need to add the two attributes (name and url) to both these maps.

'''java

    HashMap<String, String> map1 = new HashMap<String, String>();
    HashMap<String, String> map2 = new HashMap<String, String>();

    map1.put(KEY_NAME, "Any website name");
    map1.put(KEY_URL, "Any url");

    map2.put(KEY_NAME, "Any website name");
    map2.put(KEY_URL, "Any url");

'''