things to be careful about java arrays
I come a across something quite important today in a book about initialising arrays. I will directly copy/paste from the book;
Aliasing:Note carefully that an array name refers to the whole array — if we assign one array name to another, then both refer to the same array, as illustrated in the following code fragment.
int a = new int[N];
a[i] = 1234;
int b = a;
b[i] = 5678; // a[i] is now 5678.
This is something that programmers should remember all the time.
Originally published at caneldem.wordpress.com on August 18, 2014.