This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Java in General and the fly likes HashMap HashSet or ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap HashSet or ..." Watch "HashMap HashSet or ..." New topic

HashMap HashSet or ...

alan fisher

Joined: Sep 27, 2003
Posts: 5
import java.util.*;
public class PrintingContainers {
static Map mfill(Map m) {
m.put("dog", "Bosco");
m.put("dog", "Spot");
return m;
public static void main(String[] args) {
System.out.println(mfill(new HashMap()));
// output {dog=Spot}
From this program,can I deduce that HashMap can only hold the mapping from one key to one object?If it does,how can I hold a mapping from one key to some objects?
Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
Maps contain a key, value pair.
If you want to key multiple objects just make the value a Collection.
I agree. Here's the link:
subject: HashMap HashSet or ...
It's not a secret anymore!