Does a List object get passed by reference? [duplicate]

in other word: If I pass an ArrayList (java.util.ArrayList) object to a class, will it be automatically updated when I change it?

Yes

Does the List object passed by reference?

Value of reference would get passed

public updateList(List<String> names){
 //..
}

Explanation

When you call updateList(someOtherList); the value of someOtherList which is a reference will copied to names (another reference in method, bit by bit) so now both of them are referring to same instance in memory and thus it will change


See

  • Is Java “pass-by-reference” or “pass-by-value”?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)