hashMap | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

hashMap

Imagine that we want to use a hashMap that its keys and values are unspecified but the number of keys are given. We want to compare values of hashMap elements and finally, we want to print out the key related to the minimum value in this hashMap. How can we do that? Well, we only access to the hashMap using its keys and values. For example: hashMap.get("ali"); When those parameter are unspecified, how can we access to the values and keys? Can we access them using some index like arrays. Please answer my question. if possibe, please give me a sample code. Thanks a lot.

22nd Dec 2020, 3:20 PM
Mohammad Reza Moravejolahkami
Mohammad Reza Moravejolahkami - avatar
2 Answers
+ 6
Mohammad Reza Morawej You can get key on the basis of minimum value using like this String key = Collections.min(players.entrySet(), Map.Entry.comparingByValue()).getKey();
22nd Dec 2020, 4:06 PM
A͢J
A͢J - avatar
+ 2
Thanks a lot. The best for you.
22nd Dec 2020, 4:37 PM
Mohammad Reza Moravejolahkami
Mohammad Reza Moravejolahkami - avatar