title: Adding lines of varying length to a 2d arraylist
body: <p>I am looking to open a text file which is formatted as follows and to put it into an 2d arraylist where each object (and not each line) has its own index.</p>
  
  <pre><code>5
  1 a w e r s 5 2 d 6
  f s d e a 3 6 7 1 32
  2 f s 6 d
  4 s h y 99 3 s d
  7 s x d q s 
  </code></pre>
  
  <p>I have tried many solutions, most of those involving a while(scanner.hasNext()) or while(scanner.hasNextLine()) loops, assigning all the objects in a row to their own indice in a 1d arraylist, and then adding that arraylist to a 2d arraylist. But no matter what I do I do not get the result I want.</p>
  
  <p>What I am in essence trying to do is something such as the scanner .hasNext() method which only grabs the next object within a line, and will not jump to the next line. An example of one of my tries is as follows:</p>
  
  <pre><code>while (scanner.hasNextLine()) {
     ArrayList&lt;Object&gt; array = new ArrayList&lt;Object&gt;();
       while(scanner.hasNext()0 {    
  
           String line = scanner.next();
           array.add(line);
          }
  
          System.out.println(array);
          2dArray.add(array);
      }
  
      scanner.nextLine();
  }
  </code></pre>