What is the use of Hashmap in java?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the use of Hashmap in java??

Hashmap

31st Jan 2019, 2:31 PM
Sanaya
Sanaya - avatar
4 Answers
0
In a HashMap you can store data collections. You store a pair (key, value). For example you want a list of persons and their jobs. Person --> key Job --> value "John Doe"; "Teacher" "Jane Doe"; "Programmer" ... Hashmap: [John Doe = Teacher, Jane Doe = Programmer] The special thing is that you can not use a key more than one time. Adding a key that already exists, overwrites the old element. In the challenge adjacent clone letters I used a Hashmap for the letters (key) and the number of clones (values). Because I wanted the connection between the letter and their clones. And I didn't want duplicates. https://code.sololearn.com/cy5oNTefTXIb/?ref=app
31st Jan 2019, 3:04 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Thank you
31st Jan 2019, 3:54 PM
Sanaya
Sanaya - avatar
31st Jan 2019, 3:05 PM
Denise Roßberg
Denise Roßberg - avatar
0
How do you format it correctly? I've been searching for this function similar to a dictionary in python. Can you assign the same name to a key and value such as "Apple"; "Apple" ?
21st Feb 2019, 12:02 AM
brandon