Iterate through HashMap?

I have a HashMap with some elements. Now I would like to generate a String that contains each key and its correpsponding value for all the tuples in the HashMap.

I have tried:

HashMap hm =new HashMap();

hm.put("5","read");

hm.put("6","crap");

hm.put("7","bob");

Set s = hm.entrySet();

Iterator ni = s.iterator();

String ss ="";

while (ni.hasNext())

{

ss =ss + ni.next();

}

System.out.println(ss);

but that gives me:

5=read7=bob6=****

why do I get the equal signs?

[863 byte] By [lokpesta] at [2007-10-3 4:58:28]
# 1
key=value, that's what the Map.Entry toString() method does as a default.%
duffymoa at 2007-7-14 23:03:50 > top of Java-index,Java Essentials,Java Programming...
# 2
The line Set s = hm.entrySet(); doesn't give you the values, because they might not be a unique set. There's the key set, the value list, and the entry set. The entry set is key and value together.%
duffymoa at 2007-7-14 23:03:50 > top of Java-index,Java Essentials,Java Programming...
# 3

> key=value, that's what the Map.Entry toString()

> method does as a default.

>

> %

Exactly, toString method used kind of a hidden iterator which is not thread safe either, thats why its always safe to synchronize this piece of code to make it thread safe.

kilyasa at 2007-7-14 23:03:50 > top of Java-index,Java Essentials,Java Programming...