Simple question, does a list in Java hold objects by value or reference? If I place an object in a list and later on change one of its values, is the one in the list going to have the updated value?
does a list in Java hold objects by value or reference?
The List is an ordered collection that contains object references.
If I place an object in a list and later on change one of its values, is the one in the list going to have the updated value?
You can change/update only mutable objects. You cannot update immutable (e.g List<String>
) objects via their references.
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