How to iterate hashmap using foreach loop and keyset method-Method 1

preview_player
Показать описание
iterating hashmap in java example,
iterating hashmap in java using entryset,
iterating hashmap in javascript,
iterating hashmap in java using keyset,
iterating hashmap in java using iterator,
iterating hashmap in java 6,
iterating hashmap in java 5 example,
iterate hashmap in java 6 example,
iterate hashmap in java 1.4,
iterate hashmap in java 8,
iterating hashmap in java,
iterating a hashmap in java,
iterating a hashmap in java 5,
iterate a hashmap in java examples,
iterating through a hashmap in java
Рекомендации по теме
Комментарии
Автор

Thank you, thank you, thank you sir! Thank. You. Sir.

I was having trouble with this. I knew to use the keySet() in a for each loop, but didn’t know how to get the entries, which is what i wanted. When i see you use get() it all became clear.

Dreamazium
Автор

public class Solution {
public int getSum(int A, int B, int[] C) {
HashMap<Integer, Integer> map= new HashMap<>();
for(int i=0;i<A;i++){
if(map.containsKey(i)){
map.put(C[i], map.get(C[i])+1);
}
else{
map.put(C[i], 1);
}
}
int sum=0;
for(int k:map.keySet()){
if(map.get(k)==B){
sum=sum+k;
}
}
return sum;
}
}

this is not working..why

chetankumar
join shbcf.ru