0
String is passed by value or reference?
String is passed by value or reference? As it is an object I think pass by reference but when I tried to create an impure method based on strings then the string wasnât mutated .... please help đ
3 Answers
+ 3
Everything in java is passed by value
+ 1
In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable.
Once string object is created its data or state can't be changed but a new string object is created.
I guess, that
the string object that was first referenced by âreferenceâ was not altered, all that you did was make âreferenceâ refer to a new string object.
0
in java, parameters are passed by value. An object variable is in fact a reference to the content of that variable in memory, and that reference is passed by value, that's why you can modify the members of a mutable object within a function.
String are non mutable , you can't change them.