File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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!