So i have a list
List<String> names = new ArrayList<String>();
names.add("Mike");
names.add("Matthew");
names.add("Kelly");
names.add("Elon");
names.add("Paul");
names.add("Paul");
names.add("Paul");
names.add("Paul");
names.add("Kelly");
I need to count all the names and then print out 3 most popular ones in descending order
Output:
Paul : 4
Kelly : 2
Mike : 1
What have i tried? I tried from most basic stuff that i have learned to Maps, treemaps and hashmaps. With last 3 i have had some success but this i could not put them into descending order. I found some tutorials from google but they were all so complicated, yes i could just copy them and get my code working but i prefer learning from it.
Got any suggestions what would be most clearest approach. Since i have never worked with maps before i do not know much about them at the moment i am writing this. In the end the output should look like this:
Output:
Paul : 44,44%
Kelly : 22,22%
Mike : 11,11%