Objects and variablesPrimitives and references
Primitives and references
An int variable holds an integer. An array variable holds a reference to an array object. Assigning this variable to another copies the reference.
Code example
int[] a = {2, 4};
int[] b = a;
b[0] = 9; Walkthrough
Both b[0] and a[0] address the same array element. Writing 9 through b changes a[0] too.