This is a reusable code written in Java. User can just use arrayCopy() from System class to improve the performance while copying array into another array, where, arrayCopy is a inbuilt method in System class.
public class copyingArray { /** * */ public copyingArray() { super(); // TODO Auto-generated constructor stub } public static void main(String[] args) { int[][] s1=new int[][] {{1,2},{3,4,5},{6,7,8,9,10}}; int[][] s2=new int[s1.length][]; long start = System.nanoTime(); for(int i=0;i<s1.length;++i) s2[i]=s1[i]; long end = System.nanoTime(); System.out.println("arrayCopy : "+(end-start)); long start1 = System.nanoTime(); System.arraycopy(s1,0,s2,0,s1.length); long end1 = System.nanoTime(); System.out.println("For Loop : "+(end1-start1)); long start2 = System.nanoTime(); for ( int idx = 0 ; idx < s1.length; ++idx ) { s2 = (int[][])s1.clone(); } long end2 = System.nanoTime(); System.out.println("Clone : "+(end2-start2)); }