I have read about it on the forums but with many solutions available none of them seemed to work for me, i have an array list that is being filled as the program runs and at the end i want to find which string element occurred the most and simply print out which one it was. I have seen some solutions using maps and comparator but i dont know how to make them work, as they were used more for an array rather than array list and i dont know how to adapt it to mine.
The code I have:
static ArrayList<String> sequence = new ArrayList<String>();
////////////////////// ARRAY LIST ////////////////////////////////
public static void PrintArray(){
System.out.println("The Movement sequence is: " + sequence);
}
public static void FindMostCommon(){
}
elements are added in different parts of the code with ;
sequence.add("MoveLeft() ");
I need a simple way to find the most common occurring one from that list, preferably using the function i created; FindMostCommon();
Also an explaination of what is going on in the code would be appreciated :)