Tuesday, March 13, 2018

java - strange copy values from one array to another

When I watched code examples in Java, I saw a strange code:



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]);
}
}


And I don't understand, why the result "B B" is correct? When I created and initialized an arrays x and y and assigned zero element of array x is equal to B, I think that an answer must be "B A".

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...