How to count the number of occurrences of an element in a List

I’m pretty sure the static frequency-method in Collections would come in handy here:

int occurrences = Collections.frequency(animals, "bat");

That’s how I’d do it anyway. I’m pretty sure this is jdk 1.6 straight up.

Leave a Comment