title: Fastest way to remove rows in 2D Array
body: <p>I have a program where I need to remove a set of rows from a <code>byte[][]</code> array. I want to remove every row that has no zeroes in it. Right now I'm using the following methods:</p>
  
  <pre><code>public byte[][] checkRows(byte[][] grid) {
      LinkedList&lt;Integer&gt; temp = new LinkedList&lt;Integer&gt;();
      boolean willRemove = false;
      for (int y = 0; y &lt; grid.length; y++) {
          boolean tempCheck = true;
          for (int x = 0; x &lt; grid[0].length; x++) {
              if (grid[y][x] == 0) {
                  tempCheck = false;
                  break;
              }
          }
          if (tempCheck) {
              temp.add(y);
              willRemove = true;
          }
      }
  
      if (willRemove) {
          int[] rowArray = convert(temp);
          return removeRows(grid, rowArray);
      }
      return grid;
  
  }
  
  public byte[][] removeRows(byte[][] grid, int[] rows) {
      int total = rows.length;
      int current = 0;
      byte[][] retGrid = new byte[grid.length][grid[0].length];
      for (int i = total; i &lt; grid.length; i++) {
          if (current &lt; total &amp;&amp; i-total+current == rows[current]) {
              current++;
          }
          //retGrid[i] = grid[i-total+current].clone();
          System.arraycopy(grid[i-total+current], 0, retGrid[i], 0, xsize);
  
      }
      return retGrid;
  }
  
  public int[] convert(LinkedList&lt;Integer&gt; intList) {
      int[] retArray = new int[intList.size()];
      for (int i = 0; i &lt; retArray.length; i++) {
          retArray[i] = intList.get(i).intValue();
      }
      return retArray;
  }
  </code></pre>
  
  <p>This gives me a reasonably fast way of removing rows from a 2D Array and replacing them with zero rows at the top of the array. Is there any faster way to achieve the same result?</p>
  
  <p>If it's unclear what the script does, it's for removing full rows in a game of Tetris.</p>
  
  <p>UPDATE: Using <code>System.arraycopy()</code> instead of <code>clone()</code> provides a 5% performance boost for small arrays.</p>