Using a straight up java approach, we will create a Hashmap where the key will contain the element and the Map.value will hold the number of times, or count, which the element occurred. Using an enhanced for loop, we will iterate over each element checking if it exists in the map and incrementing the count.
Output
Java 8
Using a java 8 we will convert the list to a stream then call Stream.filter, an intermediate operation, passing in a lambda expression to exclude all elements that don't match "Elephants". Finally calling a the reduction count method will returns the count of elements.
Google Guava
A guava collection type Multiset, also known as a bag, contains a unique set of elements that can appear multiple times. The Multiset.count will return the number of occurrences of an element.
Output
Apache Commons
Apache commons CollectionUtils.countMatches will count the number of occurrences in a collection that match a predicate in this case "Elephants".