How do I copy a 2 Dimensional array in Java?

Since Java 8, using the streams API:

int[][] copy = Arrays.stream(matrix).map(int[]::clone).toArray(int[][]::new);

Leave a Comment