Array Index Out of Bounds error on Array List

And when the times comes to reset clonedArray back to the contents of originalArray, use arrayCopy(): :copyright:

arrayCopy(originalArray, clonedArray);

Also be aware that such cloning & copying techniques are shallow! :sweat:
And they should be used only for primitive and immutable datatypes! :warning:

Docs.Oracle.com/javase/10/docs/api/java/lang/Object.html#clone()

Thus, this method performs a “shallow copy” of this object, not a “deep copy” operation.

2 Likes