I have a SplayTreeMap of players with their levels, and I wanna print a ranking of these players based on their level.
When I use .forEach to iterate over this SplayTreeMap, it ignores the players with the same level (means that while looping over SplayTreeMap, it doesn't take into consideration values with duplicated keys).
Here is my code:
SplayTreeMap<int, String> map = SplayTreeMap<int, String>();
map[5] = 'player1';
map[2] = 'player2';
map[6] = 'player3';
map[7] = 'player4';
map[7] = 'player5';
map[7] = 'player6';
map.forEach((level, player) {
print('$player -> $level');
});
Here is the output of this code:
player2 -> 2
player1 -> 5
player3 -> 6
player6 -> 7
So I'm asking myself why it doesn't print player4 and player5.
If there is no solution to this, what's the best alternative to SplayTreeMap, to have a map, that's sorted based on its keys