I have an ArrayList, a Collection class of Java, as follows:
ArrayList
ArrayList animals = new ArrayList(); animals.add(\"bat\
Alternative Java 8 solution using Streams:
long count = animals.stream().filter(animal -> "bat".equals(animal)).count();