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

Java Java Data Structures Exploring the Java Collection Framework Maps

What is a key value ?


i really can't understand what a key value mean...can somebody explain it to me please?

4 Answers

Matias Bataglia
Matias Bataglia
1,818 Points

Imagine a dictionary, you have words and their meanings. When you use for example a HashMap in Java you have <key,value> The Key is the word and the value is the meaning of the word

Map <String,String> dictionary = new HashMap<String,String>();
dictionary.put("dog", "meaning of dog"); //<key,value>
dictionary.put("cat", "a cat is ...");

System.out.println(dictionary.get("dog"));  //access the value using the key, the data is associate to it
Jesus Mendoza
Jesus Mendoza
23,288 Points

Hey Yadin,

I'm not familiar with Java but a key value means (In my little knowledge on JavaScript) the identifier of the property of an object that can be used to access its value

For example:

// In JavaScript we can create an object using
let obj = {
   name: 'Jesus'

In the previous example, the key would be "name", which is the key that you use to acess the value corresponding to that key and the value would be "Jesus".

Also in a database you can have 2 tables where you store the key and the value. The key would be the name that you use to identify a record on a database and the value would be the value corresponding to that key.

I hope you can translate that answer to Java and can understand what I tried to explain you hahaha. Good luck!

I need explanation from java dude

ok i think i got it thanks!