codeChallenge/HashMapAmazon.java
dadgam3er c5974fe278
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s
Gitea Actions Demo / GoBuild (push) Failing after 5s
anoterCode
2024-09-11 23:21:31 -04:00

15 lines
466 B
Java

import java.util.HashMap;
public class HashMapAmazon {
public static void main(String[] args) {
int[] ar = { 3, 4, 4, 4, 3, 3, 3, 3, 6, 6, 6, 6, 1, 1, 1, 1, 9 };
HashMap<Integer, Integer> elementCount = new HashMap<>();
for (int i : ar) {
elementCount.put(i, elementCount.getOrDefault(i, 0) + 1);
}
for (Integer key : elementCount.keySet()) {
System.out.println("Element: " + key + " Count: " + elementCount.get(key));
}
}
}