This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I've got a program that needs to keep scores for each player in a game. I want to record these in a collection, but I'm not sure which collection would be best.
The number of players can vary and new players can join the game at any time. I want to keep a cumulative total for each player e.g.
If the scores occur in this order:
At the end of the game, I would like a list of the players and their total scores: e.g.
Tom = 4
Susan = 10
Joe = 5
I know I could build a HashMap and manage the accumulations myself, but I can't help worry that I might be missing a trick. If you know something better than HashMap for this problem then I'd be very grateful for your help.