I have a MultiMap that has multiple similar values:
{Entertainment=[5], Food=[2, 2, 2], Products=[11], Health & Beauty=[3]}
How do I count the total of these keys so that it counts as follows?
Entertainment = 1
Food = 3
Products = 1
Health & Beauty = 1
The number inside the array is the category id, so that Food has 3 occurrences.
Either multimap.get(key).size() or multimap.keys().count(key) should work.
Documentation
Assuming your map is declared as follows : MultiMap<String, Integer> map, you can do the following :
for (String key : map.keySet()) {
int count = map.get(key).size();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With