- 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
2 ответов
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());
}
+ 1
Bahha🐧 i get it, thanks for explaination 👍🏼