This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In the above class I have added a duplicate entryincluding that there should be four entries, But the size() returns 3, Is there a way to get the total number of entries including the duplicate entries
If it helps any, keep in mind that the HashMap's put method will return the previous value associated with the key (returning null if there was no value for the key or if the value for the key was null). In some situation this can be useful.
For something like a phone book where a key (a person's name) is very likely to have duplicate entries, I would use a double collection. Make your PhoneBook Map use the name for the key and another collection as the value. That collection would hold the phone numbers for that person. You could simply use a set which would prevent multiples of the same phone number; or use another Map with the key being the phone number type, "work", "home", "cell", etc. So you would end up with one master collection which holds a number of other collections.