For testing, I temporarily created a 'main' method in the 'Field' class. public void removeFullLines() { // Looking for partially filled rows in the // original matrix (from bottom to top) int[][] tempMatrix = new int[height][width]; // Current row index for tempMatrix int rowIndex = height - 1; for (int i = height - 1; i >= 0; i--) { int count = 0; for (int j = 0; j < width; j++) count += matrix[i][j]; // Find partially filled lines and fill tempMatrix // with them (from bottom to top) if (count > 0 && count < width) { System.arraycopy(matrix[i], 0, tempMatrix[rowIndex], 0, width); rowIndex--; } } // tempMatrix is copied into the source matrix. for (int i = 0; i < height; i++) System.arraycopy(tempMatrix[i], 0, matrix[i], 0, width); } public static void main(String[] args) { Field field = new Field(10, 5); // Randomly fill in the lines. The top two lines are only zeros. for (int i = 2; i < field.height; i++) { for (int j = 0; j < field.width; j++) { int random = (int) (Math.random() * 7); if (random != 4) field.matrix[i][j] = 1; } } System.out.println("Before calling the method:"); for (int i = 0; i < field.height; i++) System.out.println(Arrays.toString(field.matrix[i])); System.out.println(); field.removeFullLines(); System.out.println("After calling the method:"); for (int i = 0; i < field.height; i++) System.out.println(Arrays.toString(field.matrix[i])); System.out.println(); } /* CONSOLE OUTPUT(testing result): Before calling the method: After calling the method: [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 1, 1, 0, 1] [0, 0, 0, 0, 0] [1, 0, 1, 1, 1] [0, 0, 0, 0, 0] [0, 1, 1, 1, 1] [0, 0, 0, 0, 0] [0, 0, 1, 1, 1] [0, 1, 1, 0, 1] [1, 1, 1, 1, 1] [1, 0, 1, 1, 1] [1, 1, 1, 0, 0] [0, 1, 1, 1, 1] [1, 1, 1, 1, 1] [0, 0, 1, 1, 1] [1, 1, 1, 1, 1] [1, 1, 1, 0, 0] Before calling the method: After calling the method: [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [1, 1, 1, 1, 1] [0, 0, 0, 0, 0] [1, 1, 0, 0, 1] [0, 0, 0, 0, 0] [1, 0, 1, 0, 1] [0, 0, 0, 0, 0] [0, 0, 1, 1, 1] [0, 0, 0, 0, 0] [1, 1, 1, 1, 1] [1, 1, 0, 0, 1] [1, 0, 1, 1, 1] [1, 0, 1, 0, 1] [1, 1, 1, 1, 1] [0, 0, 1, 1, 1] [1, 1, 1, 1, 1] [1, 0, 1, 1, 1] Before calling the method: After calling the method: [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [0, 0, 0, 0, 0] [1, 1, 1, 1, 0] [0, 0, 0, 0, 0] [1, 1, 1, 1, 1] [0, 0, 0, 0, 0] [1, 1, 1, 1, 1] [0, 0, 0, 0, 0] [1, 1, 1, 0, 1] [0, 0, 0, 0, 0] [1, 1, 1, 1, 1] [0, 0, 0, 0, 0] [1, 1, 1, 1, 1] [1, 1, 1, 1, 0] [1, 1, 1, 1, 1] [1, 1, 1, 0, 1] [1, 1, 0, 1, 1] [1, 1, 0, 1, 1] */