Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Last active October 13, 2022 19:45
Show Gist options
  • Select an option

  • Save hackjutsu/880ed7782b3fb692c28c41c943152b75 to your computer and use it in GitHub Desktop.

Select an option

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
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