I am testing this code.
class something {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 5};
sth(a);
System.out.println(a);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
public static void sth(int[] a){
int[] b = new int[a.length];
for (int i = 0; i < a.length; i++) {
b[i] = 0;
}
a = b;
System.out.println(a);
System.out.println(b);
}
}
Expected output:
SAME MEMORY VALUE
0 0 0 0 0
What I'm Getting
[I@46d20791
[I@46d20791
[I@2c7f1f63
1 2 3 4 5
However changing the line
b[i] = 0;
to
a[i] = 0;
reflects the change to
[I@46d20791
[I@46d20791
[I@2c7f1f63
0 0 0 0 0
Help me understand what is going on there?