Both approaches create shallow copies of the array elements, which means the elements inside your arrays will still reference each other. If you want shallow copies, stick to array.clone()
.
- More readable
- Less code, uses standard Java API.
Deep copying arrays
Java 6+
this.liczby = Arrays.copyOf(liczby, liczby.length);
Older versions
System.arraycopy(liczby, 0, this.liczby, 0, liczby.length);
Test
Object[] original = { new Object(), null };
Object[] copy = new Object[2];
System.arraycopy(original, 0, copy, 0, original.length);
Object[] copy2 = Arrays.copyOf(original, original.length + 1);
copy2[1] = 2;
System.out.println(original[1]); // null
System.out.println(copy2[1]); // 2