I have players named(String name
) by their names and I have Lovers(int Lovers
).
Each player has a number of lovers. and each player has a unique name. I want a way to sort them by number and if two players or more have the same number of lovers, I want them to be sorted alphabetical order.
I thought about using a Map
and Hashmap
.
Map<String, Integer> Players= new HashMap<>();
Players.put("Christiano Ronaldo",10);
Players.put("Messi",50);
Players.put("Kaka",10);
Players.put("Ronaldinho",100);
List sortedKeys=new ArrayList(Players.keySet());
Collections.sort(sortedKeys);
I find this way is not optimal for my case.
What I expect is that get sorted by a number of lovers and if a number of lovers are equal then we sort them by name alphabetical order.