hashtable value problem
-
i m using a hash table taking a string as a key and an arraylist object as a value .. each time the arraylist value changes for the second and further entries in the hashtable all the values of the hashtable changes according to the new entry in the arraylist i.e in the end all the different keys hav the same value pair that is the last entry in the array list y is it replacing the previous values of the hashtable arraylist once its been added to the hashtable
-
i m using a hash table taking a string as a key and an arraylist object as a value .. each time the arraylist value changes for the second and further entries in the hashtable all the values of the hashtable changes according to the new entry in the arraylist i.e in the end all the different keys hav the same value pair that is the last entry in the array list y is it replacing the previous values of the hashtable arraylist once its been added to the hashtable
ArrayLists are reference types so by default variables are simply pointers to the same object in memory, so what you're storing is a pointer to the same array. What you want to look into is the
Clone
method which will return a copy of the array list, this should fix your problem. -
ArrayLists are reference types so by default variables are simply pointers to the same object in memory, so what you're storing is a pointer to the same array. What you want to look into is the
Clone
method which will return a copy of the array list, this should fix your problem.