Last active
August 5, 2023 23:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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