Copying 2d Arrays Using Loop

Similar to the single-dimensional array, we can also copy the 2-dimensional array using the for loop. For example,


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

Output for the above code is as follows


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

In the above program, notice the line,


\begin{lstlisting}
System.out.println(Arrays.deepToString(destination);
\end{lstlisting}

Here, the deepToString() method is used to provide a better representation of the 2-dimensional array.