aspose file tools*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap HashSet or ..." Watch "HashMap HashSet or ..." New topic
Author

HashMap HashSet or ...

alan fisher
Greenhorn

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: http://aspose.com/file-tools
 
subject: HashMap HashSet or ...