This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Yes, that's correct - you'll only get back the last value for that key.
Theodore Jonathan Casser
SCJP/SCSNI/SCBCD/SCWCD/SCDJWS/SCMAD/SCEA/MCTS/MCPD... and so many more letters than you can shake a stick at!
Joined: Aug 05, 2005
If you want to associate multiple values with a single key in a map, then you need to put those values in to a List and then associate that list with the key.
When you want to add a value to the map, you first check if the key already exists. If it does you retrieve the List and add the new value to it. If it doesn't then you create a List, add your new value to it and then put that key/List pair into the Map.