Copying 2d Arrays using arraycopy()

To make the above code more simpler, we can replace the inner loop with System.arraycopy() as in the case of a single-dimensional array. For example,


\begin{lstlisting}
import java.util.Arrays;
\par
class Main {
public static voi...
...ay
System.out.println(Arrays.deepToString(destination));
}
}
\end{lstlisting}

Output:


\begin{lstlisting}[[1, 2, 3, 4], [5, 6], [0, 2, 42, -4, 5]]
\end{lstlisting}

Here, we can see that we get the same output by replacing the inner for loop with the arraycopy() method.