+ 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.
2 Réponses
+ 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();
+ 2
Thanks a lot.
The best for you.