I have an array a which is constantly being updated. Let\'s say a = [1,2,3,4,5]. I need to make an exact duplicate copy of a and call
a
a = [1,2,3,4,5]
For a null-safe copy of an array, you can also use an optional with the Object.clone() method provided in this answer.
Object.clone()
int[] arrayToCopy = {1, 2, 3}; int[] copiedArray = Optional.ofNullable(arrayToCopy).map(int[]::clone).orElse(null);