On 2007-11-05 23:34:05 -0800, Kamran Shafi <ka**********@gmail.comsaid:
[...]
Note that HTableList is a global and I am creating it in another
method as HTableList = new ArrayList();
If I read your problem description correctly, you're not having trouble
with the hash tables per se, but rather with an ArrayList they contain
(though you seem to think there are more than one, Alberto is exactly
right: there's just one ArrayList).
Also ArrayList viafields and viewfields are created using new in their
respective methods.
But they are only created once in the method. So you keep adding the
same "viewfields" instance to all of your hash tables. So when you add
anything to that "viewfields" instance (which is called "ex_nodes"
where new additions are made), all of the hash tables appear to be
updated, because they all have copies of the same reference to the
single "viewfields" ArrayList you created.
I have a suspicion that the whole design is wrong, but that's between
you and your debugger. :) For the moment, I'll recommend two changes:
1) put your "viewfields" variable declaration and initialization
_inside_ the first foreach() loop if you want a new copy of the
ArrayList for each hashtable. This will cause a new "viewfields"
instance to be allocated for each "field" in "viafields", ensuring that
when you add a new "node" to the ArrayList that goes with the current
"field" in the current "htable", it only gets added in a single element
of a single hash table.
It won't fix any other basic design or implementation bugs that exist,
but at least the problem you're asking about will stop happening.
And then...
2) fix that first if() clause so that it reads "i <
HTableList.Count" instead of that ridiculously awful
"!(HTableList.Count <= i)".
Hope that helps.
Pete