Problem updating arrays in hastable.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   pmoc__2001
Posted On:   Thursday, May 6, 2004 10:45 AM

Hi, After much head scratching and goggling I have hit a brick wall. I have implemented a hashtable (recordHolder) of arrays and I am having problems updating an array pulled from the hash table without overwriting. The order is passed from XML, is numerical and will only ever be 1, 2, and 3 so a 4-element array is used starting at [1] public void addOrder(String orderName, int order, int number ) { //get array using orderName as key int[] orderList = (int[])(recordHolder.get(orderName)); //append array at element order 1,2, or 3 orderList[order] = number; //place back into hashtable recordHolder.put(orderName, orderList);    More>>

Hi,

After much head scratching and goggling I have hit a brick wall.


I have implemented a hashtable (recordHolder) of arrays and I am having problems updating an array pulled from the hash table without overwriting. The order is passed from XML, is numerical and will only ever be 1, 2, and 3 so a 4-element array is used starting at [1]



public void addOrder(String orderName, int order, int number )

			{
			

//get array using orderName as key
int[] orderList = (int[])(recordHolder.get(orderName));

//append array at element order 1,2, or 3
orderList[order] = number;

//place back into hashtable
recordHolder.put(orderName, orderList);

}



When I look at my output my array seems to overwrite itself as if the other arrays associated with each orderName are not being accessed.

Thank you to anyone who can give me some tips.    <<Less

Re: Problem updating arrays in hastable.

Posted By:   Alexander_Torstling  
Posted On:   Tuesday, May 11, 2004 06:00 PM

You might want to check that all you orderLists are not actually references to the same int-array.



That is when you fill recordHolder, you create all your int-arrays using something like:

recordHolder.put(orderName, new int[4]);



And NEW is the key concept here....



Regards.

Re: Problem updating arrays in hastable.

Posted By:   zhaohua_meng  
Posted On:   Thursday, May 6, 2004 11:10 AM

You don't need to put the array back to "recordHolder". Remove the following line and it should work:



recordHolder.put(orderName, orderList);//remove this

About | Sitemap | Contact