public class Test {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 5};
int[] b = a;
int[] c = {6, 7, 8};
a = c;
Don't be irritated by the name 'list'. The images are taken from a python visualization, but the principle is the same in Java
Array a is assigned with a new array:
Array b is assigned to the instance behind a:
Array c is assigned with a new array:
And finally a is assigned to the instance behind c, b was not re-assigned and still keeps a reference to the old a:
Images taken from a visualization on pythontutor.com