title: Using Integer[] vs. int[]
body: <p>I am trying to solve the following problem: "Write an algorithm to print all the ways of arranging eight queens on an 8x8 chess board so that none of them share the same row, column or diagonal (i.e. no two queens attack each other.)"</p>
  
  <p>I am having trouble understanding why the author used Integer[] instead of the more common int[], for example in "Integer[] columns" and "ArrayList results" which are parameters to placeQueens.  My hypothesis is that this is due to generics in Java, but I'm not entirely sure.</p>
  
  <p>Code snippet below. Link to complete code at bottom of page.</p>
  
  <pre><code>public static int GRID_SIZE = 8;
  
  /* Check if (row1, column1) is a valid spot for a queen by checking if there
   * is a queen in the same column or diagonal. We don't need to check it for queens
   * in the same row because the calling placeQueen only attempts to place one queen at
   * a time. We know this row is empty. 
   */
  public static boolean checkValid(Integer[] columns, int row1, int column1) {
      for (int row2 = 0; row2 &lt; row1; row2++) {
          int column2 = columns[row2];
          /* Check if (row2, column2) invalidates (row1, column1) as a queen spot. */
  
          /* Check if rows have a queen in the same column */
          if (column1 == column2) { 
              return false;
          }
  
          /* Check diagonals: if the distance between the columns equals the distance
           * between the rows, then they're in the same diagonal.
           */
          int columnDistance = Math.abs(column2 - column1); 
          int rowDistance = row1 - row2; // row1 &gt; row2, so no need to use absolute value
          if (columnDistance == rowDistance) {
              return false;
          }
      }
      return true;
  }
  
  public static void placeQueens(int row, Integer[] columns, ArrayList&lt;Integer[]&gt; results) {
      if (row == GRID_SIZE) { // Found valid placement
          results.add(columns.clone()); 
      } else {
          for (int col = 0; col &lt; GRID_SIZE; col++) {         
              if (checkValid(columns, row, col)) {
                  columns[row] = col; // Place queen
                  placeQueens(row + 1, columns, results); 
              }       
          }
      }
  }
  </code></pre>
  
  <p>Source for question/code: Cracking the Coding Interview. Link to complete code: <a href="https://github.com/gaylemcd/ctci/blob/master/java/Chapter%209/Question9_9/Question.java" rel="nofollow">https://github.com/gaylemcd/ctci/blob/master/java/Chapter%209/Question9_9/Question.java</a></p>