Deep copying a 2d array in Java

602    Asked by CarolynBuckland in Python , Asked on Jul 27, 2021

Can someone guide me, how to perform a deep copy of a boolean array? I tried using .clone() on my 2d boolean array but it was a fail. Any suggestions are welcomed. How java copy 2d array?

 

Answered by Chris Dyer

To copy 2d array copying you will have to iterate over your 2 dimensional array. You can refer the following code for the same:

public static boolean[][] deepCopy(boolean[][] org) {
    if (org == null) {
        return null;
    }
    final boolean[][] res = new boolean[org.length][];
    for (int i = 0; i < org xss=removed>

Your Answer

Interviews

Parent Categories