Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (10.2k points)

I am trying to implement a dictionary (as in the physical book). I have a list of words and their meanings.

What data structure / type does Java provide to store a list of words and their meanings as key/value pairs.

How, given a key, can I find and return the value?

1 Answer

0 votes
by (46k points)

You'll require a Map<String, String>. Classes that perform the Map interface involve (but are not restricted to):

Each is created/optimized for certain conditions (go to their respective docs for more info). HashMap is apparently the most common; the go-to default.

For example (using a HashMap):

Map<String, String> map = new HashMap<String, String>();

map.put("dog", "type of animal");


type of animal

Related questions

0 votes
1 answer
asked Jun 20, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
0 votes
2 answers

Browse Categories