title: How to add user input into an ArrayList until a keyword triggers it to stop?
body: <p>So I'm trying to write a Java program that allows a user to input words at the command line.  The program should stop accepting words when the user enters "STOP".  Store the words in an ArrayList.  The word STOP should not be stored in the list.</p>
  
  <p>Next, print the size of the list, followed by the contents of the list.</p>
  
  <p>Then, remove the first and last words stored in the list, but only if the list has a length greater than two.  Finally, reprint the contents of the list.</p>
  
  <pre><code>import java.io.*;
  import java.util.ArrayList;
  import java.util.Scanner;
  public class t2_lesson1_template {
  
      public static void main (String str[]) throws IOException
      {
          ArrayList&lt;String&gt; list  = new ArrayList&lt;String&gt;();
  
          Scanner scan = new Scanner(System.in);  
  
  
          do 
          {
              System.out.println("What would you like to add to the list?"); 
              String input = scan.nextLine();
              list.add(input);
          }
  
          while( scan.nextLine() != "STOP");
  
  
         if ( list.size() &lt; 2)
         {
          System.out.println(list);
          System.out.println(list.size());
         }
         else
         {
          list.remove(0);
          list.remove(list.size()-1);
          System.out.println(list);
          System.out.println(list.size());
         }
     }
  
  }
  </code></pre>
  
  <p>It keeps on prompting the question, but never recognizes when "STOP" is the input.  If somebody could please help me figure out what's wrong, it'd help a lot.  Thank you!</p>