How to print the value of key knowing the value of value in Java? Как вывести значение ключа зная значение value в hashmap Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to print the value of key knowing the value of value in Java? Как вывести значение ключа зная значение value в hashmap Java?

I created a HashMap with 3 values. It is necessary that the program displays the String key behind the maximum Integer value, using iteration of the value value, translates it into a LinkedList, and finds the maximum value through if. I know, it's trite, probably, but the main thing is to cope with the task. So here's how to output the key of a String after a certain index. As for value, you can use get, but for key I did not find a similar way. I will be very grateful for your support! Я создал HashMap на 3 значения. Нужно чтобы программа выводила ключ String за максимальным значением Integer, с помощью итерации значения value перевёл в LinkedList, нашёл максимальное значение через if. Знаю, банально, наверное, но главное справиться с задачей. Так вот, как вывести ключ String за определённым индексом. Как для value можно использовать get, но для key не нашёл похожего способа. Буду очень благодарным за поддержку

1st Apr 2022, 9:12 AM
Mykhailo Symonenko
Mykhailo Symonenko - avatar
2 Answers
+ 2
What approach you are following..? When you try for max, you use map.get("key") to compare, save this "key" along with value. Finally use this key. There is no direct method to get key in hashMap. Hope it helps...
1st Apr 2022, 9:20 AM
Jayakrishna 🇮🇳
1st Apr 2022, 11:45 AM
JaScript
JaScript - avatar