Considering an ArrayList of String's containing
animalsArray[dog, cat, dog, dog, cat, duck, duck, dog]
I could easily use HashMap's to find the most common String, using the HashMap value as a counter, and the key to store the animal name.
If the ArrayList was sorted
[dog, dog, dog, dog, cat, cat, duck, duck]
What is the easiest way to find the most common element without using Hashmaps? I was thinking about using a for loop comparing animalArray.get(i) with animalArray.get(i-1) but I wasn't able to develop this solution. And what are the advantages, if there are any, of having a sorted ArrayList when we need we need to find the most common element?