- 1

Iteration through hashmap

Hey guys, i just try to complete last project java, iteration through hashmap. But i still dont get it, please help https://code.sololearn.com/cla8XY9pTV1r/?ref=app

6th Mar 2021, 2:26 PM
Semmy Rajita
Semmy Rajita - avatar
2 Antworten
0
a lazy fix, you can save the max value each time you loop. with that condition maxEntry will be updated only when there's a new max value. cast entry.getValue() to int for the comparison to work. int mxv = 0; for (Map.Entry entry : players.entrySet()){ if ( (int)entry.getValue() > mxv){ maxEntry = entry; mxv = (int)entry.getValue(); } System.out.println(maxEntry.getKey()); }
6th Mar 2021, 2:57 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Bahha🐧 i get it, thanks for explaination 👍🏼
7th Mar 2021, 4:57 PM
Semmy Rajita
Semmy Rajita - avatar