title: Java ArrayList - Check if list is empty
body: <p>How can I check if a list is empty? If so, the system has to give a message saying <strong>List is empty</strong>. If not, the system has to give a message saying <strong>List is not empty</strong>.
  Users can enter numbers, <code>-1</code> to stop the program.
  This is the code I now have, but this doesn't work, it always says 'List isn't empty'.</p>
  
  <pre><code>import java.util.*;
  import javax.swing.JOptionPane;
  
  public class ArrayListEmpty 
  {
      public static void main(String[] args) 
      {
          List&lt;Integer&gt; numbers = new ArrayList&lt;Integer&gt;();
          int number;
          do {
              number = Integer.parseInt(JOptionPane.showInputDialog("Enter a number (-1 to stop)"));
              numbers.add(number);
          } while (number != -1);
          giveList(numbers);
      }
  
      public static void giveList(List&lt;Integer&gt; numbers)
      {
          if (numbers != null)
              JOptionPane.showMessageDialog(null, "List isn't empty");
          else
              JOptionPane.showMessageDialog(null, "List is empty!");
      }
  }
  </code></pre>