wood burning stoves*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How objects are stored in arraylist" Watch "How objects are stored in arraylist" New topic

How objects are stored in arraylist

Roshnara Rose

Joined: Nov 08, 2005
Posts: 15

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?

Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: How objects are stored in arraylist
Similar Threads
Pass ArrayList To Oracle
ArrayList problem
clone of ArrayList
Any Link Between ArrayList and HashMap
How to typecast an object which is of unknown class type at runtime?