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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With