[PJUG Javamail] TreeMap() behaves differently inside a for loop than out -- I don't get it
Rob Tanner
rtanner at linfield.edu
Sat Dec 15 00:01:48 UTC 2007
Hi,
Maybe I just need a copy of Java for Dummies.
I am generating some data within a for loop and adding the data -- a
three cell String[] array -- to a TreeMap() keyed with a numeric date
string, YYYYMM. Inside the for loop, values entered in the map can be
retrieved using the appropriate key (i.e. the mapping is good).
Complete the for loop and fall through, it doesn't matter what key I use
(so long as there is a mapping), I get the last data value that was
entered and not the one that should map to the key. It's not like this
is major rocket science. The for loop makes 20 passes and I do 4 puts
per pass. Here is a sample of the code for a single entry ( the "i" is
the loop variable):
key = new Integer(i).toString() + "04";
codes[0] = new Integer(i).toString() + " Summer";
codes[1] = new Integer(i).toString() + "SU";
codes[2] = null;
semesters.put(key, codes);
Debugging in Eclipse does not lead me to an answer unless someone can
tell me exactly how to view the mappings in the TreeMap(). I went so
far as the retrieve each entry into the map right after I enter it, and
at that point it's mapped correctly. It's only after I fall through the
bottom of the for loop that the mapping gets screwed up.
Any ideas about what might by wrong?
Thanks,
Rob
More information about the Javamail
mailing list