Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java beginner- is an arraylist call by reference

Tags:

java

arraylist

In a java program, I want 3 arraylist variables to be modified by a call to a single function.

Am I correct in thinking that if I pass these 3 arraylists as parameters to that function, then all 3 can be modified within the function? Or will I have to modify each arraylist in a separate function, and specify that array list as the return value, to ensure that it is modified.

like image 375
Arvind Avatar asked Jan 16 '23 13:01

Arvind


1 Answers

Am I correct in thinking that if I pass these 3 arraylists as parameters to that function, then all 3 can be modified within the function?

In a word, yes.

It is worth noting that the "by reference" terminology in the title of your question is not exactly right. In Java, everything is passed by value, including object references. It is the fact that the three ArrayList parameters are references themselves that makes any changes made to the lists propagate back to the caller.

like image 124
NPE Avatar answered Jan 19 '23 03:01

NPE