To copy an array, you need to create a new array and copy the elements manually or with arrayCopy() or use java.util.Arrays.copyOf. Otherwise both a and b refer to the same instance, as you found out yourself. This also applies to all objects (exception are primitives like int, boolean, or float, which are copied).
2 Likes