Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HashMap Question

43 views
Skip to first unread message

dou...@kc.rr.com

unread,
Mar 24, 2005, 5:12:37 PM3/24/05
to
I have a HashMap that is storing form data that will later be inserted
into a database. I have been able to create the HashMap just fine, but
I wanted to be able to take my HashMap and just "dump" it out to the
screen to make sure that everything is working as I expect. (It was
really to easy to code so I think that I may be mising something).

This is a piece of the code where I am updating the HashMap:
if ( map.containsKey(temp))
{
// get MyData
MyDataTmp = (DSNdata)map.get(temp);
if( tempAction.equalsIgnoreCase("alias"))
{
MyDataTmp.putAlias("Y");
}
else if( tempAction.equalsIgnoreCase("load"))
{
MyDataTmp.putLoad("Y");
}
// delete the key and re add it
map.remove(temp);
map.put(temp, MyDataTmp);

}

This is where I am trying to "print" the hashmap:
out.println(map.size());
// Iterate over the keys in the map
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
// Get key
Object Key = it.next();
System.out.println(Key);
System.out.println("Hi");
}

// Iterate over the values in the map
it = map.values().iterator();
while (it.hasNext()) {
// Get value
Object Value = it.next();
System.out.println(Value);
System.out.println("Hi");
}


The println(map.size()) returns a number that is changing based on the
amout of data being processed by the form. This number does change
based on the amount of data that is being sent to it.

Can anyone help here? I added the "Hi" to the loop to see if it even
is going into the loop, and it dosent, so I would assume that the
hasNext() is returning false.

Thanks is advance for help,
Doug

Ted Dunning

unread,
Mar 25, 2005, 2:11:11 PM3/25/05
to

First of all, you can always print the contents of any Map by just
using println on the map itself ... you don't have to iterate through
it.

The biggest recommendation I have for you is to get and use a good IDE
with a debugger. That will let you see where you are going wrong. I
and many others strongly prefer IntelliJ IDEA, but it costs money
(after the eval runs out, that is). They have a beta program which
will let you use their software until it is released, but you have to
put up with the fact that they are changing the problem relatively
often.

Eclipse is the other major contender and is free. I last tried it
quite some time ago and got a bad taste. Presumably it is massively
better now.

0 new messages