title: How to create 2D ArrayList and add elements
body: <p>I have a small program that hold pairs of states and their capitals in 2D array. Below this program:</p>
  
  <pre><code>public class StateCapitals {
  
  public static void main(String[] args) {
      String[][] answers = {
              {"Alabama", "Montgomery"},
              {"Alaska", "Juneau"},
              {"Arizona", "Phoenix"},
              {"Arkansas", "Little Rock"},
              {"California", "Sacramento"},
              {"Colorado", "Denver"},
              {"Connecticut", "Hartford"},
              {"Delaware", "Dover"},
              {"Florida", "Tallahassee"},
              {"Georgia", "Atlanta"}
      };
  
  
      int correctCount = 0;
  
      for (int i = 0; i &lt; answers.length; i++) {
  
  
          System.out.print("What is the capital of " + answers[i][0]);
  
          Scanner input = new Scanner(System.in);
  
          String userInput = input.nextLine();
  
  
  
          for (int j = 0; j &lt; answers[i].length - 1; j++) {
              System.out.println("The correct answer should be " + answers[i][j + 1]);
  
              if(userInput.equals(answers[i][j + 1]))
                  correctCount++;
  
          }
  
  
      }
  
      System.out.println("The correct count is " + correctCount);
      }
  }
  </code></pre>
  
  <p>I need to replace regular 2D array with <code>List&lt;List&lt;String&gt;&gt; super2dArray = new ArrayList&lt;ArrayList&lt;String&gt;&gt;()</code>. </p>
  
  <p>I found some threads on stackoverflow how to add array that I want. Here is links: <a href="https://stackoverflow.com/questions/16956720/how-to-create-an-2d-arraylist-in-java">How to create an 2D ArrayList in java?</a> and<a href="https://stackoverflow.com/questions/10768170/how-do-i-declare-a-2d-string-arraylist/10768198#10768198">How do I declare a 2D String arraylist?</a>. But these discussions didn't explain how to add elements in each ArrayList. The best that I can do to create new ArrayList then add some elements and finally attached ArrayList to another one. They didn't explain how to add elements to 2D ArrayList.</p>