title: How can I efficiently shift everything in a 2d array down by a given amount?
body: <p>I have a 2d char array that represents a game board similar to tetris. I remove blocks from the board when there are three or more in a row. Now, I want to basically remove the spaces in between the blocks. So I want to start at the bottom right and go up each column, and them move to the next column. When I reach a blank '.' piece, I need to shift everything down.</p>
  
  <p>Here are the methods I'm trying to use</p>
  
  <pre><code>public void boardGravity() {
  
          for (int j = c - 1; j &gt; 0; j--) {
              for (int i = r - 1; i &gt; 0; i--) {
                  if (board[i][j] != '.') {
                      int count = 0;
                      while(isEmpty(i + count + 1, j)) {
                          count++;
                      }
                      board[i + count][c] = board[r][c];
                      board[r][c] = '.';
                  }
              }
          }
      }
  
      public boolean isEmpty(int row, int col) {
          if (row &gt;= 0 &amp;&amp; col &gt;= 0 &amp;&amp; board[row][col] == '.') {
              return true;
          }
          return false;
      }
  </code></pre>
  
  <p>I'm having a hard time wrapping my head around the logic of this! I can't find anything similar enough to this either.</p>
  
  <p>Edit: Here is an example output:</p>
  
  <pre><code>New Board Created!
  .....
  .....
  .....
  .....
  .....
  .....
  
  .....
  .....
  .....
  a....
  a....
  a....
  
  a....
  c....
  b....
  a....
  a....
  a....
  
  a....
  c....
  b....
  .....
  .....
  .....
  
  a....
  c....
  b....
  .....
  .....
  .....
  </code></pre>
  
  <p>In the last board print, I need the characters in the top left to be shifted to the bottom.</p>