Skip to content

Instantly share code, notes, and snippets.

@TheGreatJoules
Last active August 5, 2023 23:40
Show Gist options
  • Save TheGreatJoules/e4dc6d879d69e68458d049598b13dfd4 to your computer and use it in GitHub Desktop.
Save TheGreatJoules/e4dc6d879d69e68458d049598b13dfd4 to your computer and use it in GitHub Desktop.
[Java/Copy] A simple code explanation of the representation of shallow and deep copy arrays. #java #copy
/**
* ShallowCopy
*/
int[] a = new int[] {1,2,3};
int[] b = new int[a.length];
b = Arrays.copyOf(a, a.length);
/**
* DeepCopy
*/
int[] c = new int[] {4,5,6};
int[] d = new int[c.length];
System.arraycopy(c, 0, d, 0, d.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment