Last active
October 13, 2022 19:45
-
-
Save hackjutsu/880ed7782b3fb692c28c41c943152b75 to your computer and use it in GitHub Desktop.
[Deep copy of a 2d array in Java] http://stackoverflow.com/a/1564856/3697757
This file contains hidden or 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
| public static boolean[][] deepCopy(boolean[][] original) { | |
| if (original == null) { | |
| return null; | |
| } | |
| final boolean[][] result = new boolean[original.length][]; | |
| for (int i = 0; i < original.length; i++) { | |
| result[i] = Arrays.copyOf(original[i], original[i].length); | |
| // For Java versions prior to Java 6 use the next: | |
| // System.arraycopy(original[i], 0, result[i], 0, original[i].length); | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment