Just started to learn Java, and saw that both string and array are reference types. I don't understand the following issue:
String a = "a1";
String b = "a2";
a=b;
a = "rrr";
System.out.println(a);
System.out.println(b);
int[] arr1 = {1,2,3};
int[] arr2 = arr1;
arr2[0]= 19;
System.out.println(arr1[0]);
When I print it, I get : "rrr" "a2" 10
when using arrays - I understand that they are both pointing on the same object, so if I change the cell - I see the difference both at arr1 and arr2.
regarding "string" - from my understanding when I do : a=b it shouldn't be : "let a
point on the same object as b
is pointing" - meaning if I change a that they both need also to be changed?
Thanks!!