@Test public void testCopyMatrix(){ String[][] foo = new String[2][]; foo[0] = new String[]{"Hi", "first row"}; foo[1] = new String[]{"Hello", "second row", "raws do not have to have same length"}; String[][] copy = CopyExample.copy(foo); checkSameData(foo, copy); String WRONG = "WRONG"; copy[0] = new String[]{WRONG}; assertEquals(2, foo[0].length); assertNotEquals(WRONG, foo[0][0]); assertEquals("Hi", foo[0][0]); copy[1][0] = WRONG; assertNotEquals(WRONG, foo[1][0]); assertEquals("Hello", foo[1][0]); }
public static String[] copy(String[] input){ if(input == null){ return null; } String[] output = new String[input.length]; for(int i=0; i<output.length; i++){ output[i] = input[i]; } return output; }
CopyExample { public static String[] copy(String[] input){ if(input == null){ return null; } String[] output = new String[input.length]; for(int i=0; i<output.length; i++){ output[i] = input[i]; } return output; } }
CopyExample { public static String[] copy(String[] input){ if(input == null){ return null; } String[] output = new String[input.length]; for(int i=0; i<output.length; i++){ output[i] = input[i]; } return output; }  }
CopyExample { public static String[] copy(String[] input){ if(input == null){ return null; } String[] output = new String[input.length]; for(int i=0; i<output.length; i++){ output[i] = input[i]; } return output; }  static String[] copyWrong(String[] input); static String[] copy(String[] input); static String[][] copyWrong(String[][] input); static String[][] copy(String[][] input); }
CopyExample { public static String[] copy(String[] input){ if(input == null){ return null; } String[] output = new String[input.length]; for(int i=0; i<output.length; i++){ output[i] = input[i]; } return output; }  static String[] copyWrong(String[] input); static String[] copy(String[] input); static String[][] copyWrong(String[][] input); static String[][] copy(String[][] input);  }