I have an ArrayList
that looks like this:
ArrayList<TravelData> listOfTravels;
and TravelData
object contains the following elements
int id;
String groupName;
String guideName;
This is how I initialize the arrayList:
listOfTravels.add(new TravelData(1,"group a", "Ross"));
listOfTravels.add(new TravelData(2,"group a", "Chandler"));
listOfTravels.add(new TravelData(3,"group a", "Monica"));
listOfTravels.add(new TravelData(4,"group b", "Phoebe"));
listOfTravels.add(new TravelData(5,"group b", "Rachel"));
listOfTravels.add(new TravelData(6,"group c", "Joey"));
listOfTravels.add(new TravelData(7,"group c", "Rachel"));
listOfTravels.add(new TravelData(8,"group d", "Chandler"));
I want to get the top 3 most common groups and guides on that list. In this example:
Top 3 groups: "group a", "group b", "group c"
Top 3 guides: "Rachel", "Chandler", "Ross"
(The third place of guides could be anyone else because Ross, Monica, Phoebe and Joey have the same appearance count).
I found good answers like how to get the most common element in a list but it's only good for ArrayList
of integers and shows only the first most common element.