aspose file tools*
The moose likes Java in General and the fly likes How objects are stored in arraylist 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 » Java in General
Bookmark "How objects are stored in arraylist" Watch "How objects are stored in arraylist" New topic
Author

How objects are stored in arraylist

Roshnara Rose
Greenhorn

Joined: Nov 08, 2005
Posts: 15
Hi,

I would like to know how added objects are stored in arraylist.
Java passes objects by reference. So i added an object to arraylist and then set it to null. The arraylist has it.
Is pass by value happening here? Is the pass by reference is only for user defined methods?

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Everything in Java is passed by value. The thing is, for objects, it is the reference to the object that is copied. So in your example, the ArrayList has a copy of the reference to the object, so after you set your own reference to null there is still the ArrayList reference to the object.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: How objects are stored in arraylist