Question: Hello, please help me understand these codes public static void countFrequencies(ArrayList list) { // hashmap to store the frequency of element Map hm = new
Hello, please help me understand these codes
public static void countFrequencies(ArrayList
{
// hashmap to store the frequency of element
Map
for (String i : list) {
Integer j = hm.get(i);
hm.put(i, (j == null) ? 1 : j + 1);
}
// displaying the occurrence of elements in the arraylist
for (Map.Entry
System.out.println("Element " + val.getKey() + " "
+ "occurs"
+ ": " + val.getValue() + " times");
}
}
Can someone explain to me what this for loop
for (String i : list) {
Integer j = hm.get(i);
hm.put(i, (j == null) ? 1 : j + 1);
}
does, and this for loop does?
for (Map.Entry
System.out.println("Element " + val.getKey() + " "
+ "occurs"
+ ": " + val.getValue() + " times");
}
}
I found these on a website but i am having a hard time to understand what these does.
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
