title: Is there a way to store user input from an Scanner object in an array list without determining the array size beforehand?
body: <p>I’m struggling to write a piece of code where I’ll use System.out.print to ask the user to type Strings. Those Strings will be stored in an arrayList. The user can type as many words as they want so the arrayList can’t have a predefined length, and I can’t ask the user how many words they are going to type, because the program needs to have those Strings as its only input.</p>
  <p>I have used a <code>while(scan.hasNext())</code> to keep adding Strings to the arrayList, but can’t figure out how to break the while loop. This is what I’ve come up with so far. I know it's wrong and I would appreciate any help.</p>
  <pre><code>public class ArrayListTest {
  
      public static void main(String[] args) {
  
          ArrayList&lt;String&gt; words = new ArrayList&lt;String&gt;();
          Scanner scan = new Scanner(System.in);
          System.out.println(&quot;Please type your list of word and press Enter when it’s finished &quot;);
  
          while (scan.hasNext()) {
              words.add(scan.next());
  
              if (System.lineSeparator() == true) {
                  break
              }
          }
      }
  }
  </code></pre>