aspose file tools*
The moose likes Beginning Java and the fly likes an Object array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "an Object array" Watch "an Object array" New topic
Author

an Object array

Castulo Ruiz
Greenhorn

Joined: May 08, 2009
Posts: 12
I have this an array of linked list. the linked list is an ADT.
When make the array and store the linked list well it does not work. the loop stops there is nothing inside.
not sure what is going on.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
You are calling makeEmpty(). Doesn't that remove everything you have just added?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

The assignment row[i] = temp doesn't create a copy of the List object temp is referring to, it only copies the reference. Afterwards, both row[i] and temp refer to the same object. And after the loop, you have n references in the List plus the extra temp reference, all referring to one single List object. So when you clear temp, you're clearing all List objects - the only one there is.

The solution is easy - create a new copy each time:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: an Object array