File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes an Object array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 32639
    
    4
You are calling makeEmpty(). Doesn't that remove everything you have just added?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: an Object array
 
Similar Threads
Two Dimensional Arrays
Sorting a row in a two deminsional array
Comparing Values of multi dimensional array
u_int8_t in java
Turn Based Strategy Games