title: java.lang.IndexOutOfBoundsException with null arrayList
body: <p>My code works when tested with an <code>ArrayList</code> that contain objects but puts out the following error when the <code>arrayList</code> is empty: </p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
  </code></pre>
  
  <p>What am I getting wrong?</p>
  
  <p>Gets the <code>Rectangle</code> with the smallest area
   return the rectangle with the smallest area or <code>null</code> if
   there are no rectangles.</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class RectangleList 
  {
  
      ArrayList&lt;Rectangle&gt; list = new ArrayList&lt;Rectangle&gt;();
  
      public RectangleList(ArrayList&lt;Rectangle&gt; theList) 
      {
          list = theList;
      }
  
      /**
       * Gets the Rectangle with the smallest area
       * 
       * @return the rectangle with the smallest area or null if there are no
       *         rectangles
       * 
       */
      public Rectangle smallestArea() 
      {
  
          Rectangle currentsmallestRectangle = list.get(0);
          for (int i = 0; i &lt; list.size(); i++) {
  
              Rectangle nextRectangle = list.get(i);
  
              if (list.isEmpty()) {
                  return null;
              } else if ((nextRectangle.getWidth() * nextRectangle.getHeight()) &lt; (currentsmallestRectangle
                      .getWidth() * currentsmallestRectangle.getHeight())) {
                  currentsmallestRectangle = nextRectangle;
  
              }
  
              return currentsmallestRectangle;
          }
  
      }
  }
  </code></pre>