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?
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.