Good day. I read about the challenge by value and came across two examples. 1st:
public class Application { public static void main(String[] args) { String[] x = {"A"}; String[] y = x; x[0] = "B"; System.out.print(x[0] + " " + y[0]); } } Here everything seems to be clear. The reference to the string array "y" will coincide with the reference to the array "x" and copying will occur and the answer will be "BB". But here is a second example:
public class Application { public static void main(String[] args) { String x = "A"; String y = x; x = "B"; System.out.print(x + " " + y); } } Here, for some reason, the answer is "BA", although I thought that the correct answer would be "BB". The line of reasoning was the same as in the first example. Can you please tell me what the trick is in this example? After all, a String is a class, not a type in Java, and in both examples we create an instance of the String class.
![String [] x = {"A"};](https://i.imgur.com/13vkI4F.png)
![String [] y = x;](https://i.imgur.com/COhbMlG.png)
![x [0] = "B";](https://i.imgur.com/xVRIN8q.png)


