This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "an Object array" Watch "an Object array" New topic

an Object array

Castulo Ruiz

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

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

Joined: Oct 27, 2005
Posts: 19655

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:

How To Ask Questions How To Answer Questions
Don't get me started about those stupid light bulbs.
subject: an Object array
Similar Threads
u_int8_t in java
Turn Based Strategy Games
Comparing Values of multi dimensional array
Sorting a row in a two deminsional array
Two Dimensional Arrays