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 trialBen Morse
6,068 Points"Key" what does he mean?
When talking about the "key variable" when passing data through the intent method, I am still unclean about what "key" means. If you were to define it, how would you?
code: intent.putExtra("name", name);
Is "name" the declaring variable that is going to hold a value(name) as it is passed to to the next activity?
1 Answer
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsI believe he is referring to a key value pair. A key is an identifier, a value is a variable or some sort of data linked to that key.
Key1: Value1
Key2: Value2
By referencing Key1 we can get the value associated with it (Value1)
In this example:
intent.putExtra("name", name);
The first part, "name" is the key.
The second part, name is a variable (a string in this case) which was defined earlier in the code.
This example may help.
I'm not great with Java so not sure of the syntax but the concept of key value pairs is the same in many different languages.
Hope this helps :)
Ben Morse
6,068 PointsBen Morse
6,068 PointsSo that Key is Identifying with the value correct??
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsJames Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsYep pretty much. It's also known as a name:value pair. The key is just a name that refers to a value.
We can use the key Color to get the value "Blue"
Hope that makes sense.