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!

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


Arcee Palabrica
Arcee Palabrica
8,100 Points

What's a "key"?

Hey guys, Quick question. What's the role of the key "name" in this code?

intent.putExtra("name", name);

Thanks so much :)

2 Answers

Hi there,

Data is often held in unordered collections in pairs. A key and a value. The data you want is the value which is accessed by passing the corresponding key to the collection.

The data can be anything, from a simple string to large chunks of data. The key is usually a simple representation of what it is accessing.

So, Intents can have multiple Extras. They are each made up of a key & a value. You access the piece of extra you want by passing the key in; the data you want is then returned. Unlike an ordered collection, e.g. an array where you can access the first, second, 50th element, unordered collections, e.g. dictionaries, are accessed by passing keys to unlock the value.

I hope that helps!


Arcee Palabrica
Arcee Palabrica
8,100 Points

Steve Hunter Alright thanks man! that explains it well... So when you say "a simple representation" of what it's accessing you mean you can name it whatever you want right?

Absolutely, yes. You can call it whatever you want. Here's a dictionary in the Swift language:

var iceCream = ["CC":"Chocolate Chip", "AP": "Apple Pie", "PB": "PeanutButter"]

Python would be similar:

values = {"name": "Michelangelo", "food": "PIZZA"}

Ruby would look like:

stuff = {'name' => 'Zed', 'age' => 39, 'height' => 6 * 12 + 2}


Arcee Palabrica
Arcee Palabrica
8,100 Points

Steve Hunter awesome! thanks again man... have a great day! :)