title: Having difficulty adding elements to 2-dimensional array
body: <p>I have a .txt file that looks like this:</p>
  
  <pre><code>Mathematics:MTH105
  Science:SCI205
  Computer Science:CPS301
  ...
  </code></pre>
  
  <p>And I have an assignment that requires that I read file and place each line into an array that should look like this:</p>
  
  <pre><code>subjectsArray[][] = {
     {"Mathematics", "MTH105"},
     {"Science", "SCI205"},
     {"Computer Science", "CPS301"}
  };
  </code></pre>
  
  <p>I am getting a compile error when I attempt to add the contents of the file to a 2-dimensional array:</p>
  
  <pre><code>private static String[][] getFileContents(File file) {
  
      Scanner scanner = null;
      ArrayList&lt;String[][]&gt; subjectsArray = new ArrayList&lt;String[][]&gt;();
  
      //Place the contents of the file in an array and return the array
      try {
          scanner = new Scanner(file);
          int i = 0;
  
          while(scanner.hasNextLine()) {
  
              String line = scanner.nextLine();
              String[] lineSplit = line.split(":");
  
              for(int j = 0; j &lt; lineSplit.length; j++) {
                  subjectsArray[i][j].add(lineSplit[0]); //The type of the expression must be an array type but it resolved to ArrayList&lt;String[][]&gt;
              }
  
              i++;
          }
          return subjectsArray;
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } finally {
          scanner.close();
      }
      return null;
  }
  </code></pre>
  
  <p>Error reads:</p>
  
  <pre><code>The type of the expression must be an array type but it resolved to ArrayList&lt;String[][]&gt;
  </code></pre>
  
  <p>I am new to multi-dimensional arrays and not sure what it is I'm doing wrong. Can someone tell me what I'm doing wrong?</p>