title: Create 2D array of Lists in Java
body: <p>I'm trying to create a 2D array of lists for a Sudoku. Essentially 81 lists each containing possible solutions to that box in the Sudoku grid. I've tried multiple declarations so far, but whenever I try to add values to a list it returns a null pointer exception. Here is an example, simply populating each of the lists with the numbers 1-9.</p>
  
  <pre><code>List&lt;Integer&gt;[][] sudoku = (List&lt;Integer&gt;[][]) new List[9][9];
  
  for (int i = 0; i &lt; 9; i++) {
          for (int j = 0; j &lt; 9; j++) {
              for (int k = 1; k &lt; 10; ) {
                  sudoku[i][j].add(k);
              }
          }
  }
  </code></pre>
  
  <p>I'm not even positive a 2D array of lists is the optimal way to go about this, but I've done everything from scratch (with a relatively low knowledge of java) so far so I'd like to follow through with this method. The original code looked as follows:</p>
  
  <pre><code>List[][] sudoku = new List[9][9];
  </code></pre>
  
  <p>Research quickly revealed that this wouldn't cut it.</p>
  
  <p>Thank you in advanced for any help!</p>