• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList object is being overwritten  RSS feed

 
jman williams
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hey everyone,

I am trying to add Node objects to the arraylist children but it appears that when the second object is added to the arraylist the first node object is being overwritten could someone please assist me with correcting this issue
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What makes you think the first value appears to be being overwritten? Have you tried printing out the contents of the ArrayList on each iteration to see if it is growing?
 
jman williams
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the arraylist grows insize but the first object values seems to become the same as the next object added values so when I print the arraylist both objects print the same state. When I print directly from the state variable without adding to a list they are different.
 
jman williams
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. I was incorrectly copying the 2d arraylist
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!