how to count the number of occurrences of an element in a arraylist in java

Java
ArrayList<String> listName = new ArrayList<>();
int occurrences = Collections.frequency(listName, "element");int occurrences = Collections.frequency(animals, "bat");
Source

Also in Java: