title: Can an ArrayList contain more elements than the maximum value of int?
body: <p>I was testing how Java (SE7) would deal with the <code>int</code> that exceed its maximum value through the following code:</p>
  
  <pre><code>int index = 2147483647;//the maximum value of int
  long size = 2147483648L; //More than the maximum value of int by 1
  int safeCounter=0; //To prevent the infinite loop
  while (index&lt;size)
  {
      System.out.println("Index now is : "+index);//show the int value
      index++; //increment the int value
      safeCounter++; //increment the number of desired loops
      if (safeCounter==3){
          break;//to break the loop after 3 turns
      }
  
  }
  </code></pre>
  
  <p>and what I got is:</p>
  
  <p>Index now is : 2147483647
  Index now is : -2147483648
  Index now is : -2147483647</p>
  
  <p>So after being confused by this, (which if I don't use the <code>safeCounter</code> it would keep going forever between the maximum value and the minimum value of <code>int</code> -- and no exception is thrown) I was wondering how would an <code>ArrayList</code> handle a situation where the the number of elements exceed the maximum value of <code>int</code> (assuming that the heap space is not an issue)?
  And if <code>ArrayList</code> can't handle this, Is there other data structure which can?</p>
  
  <hr>
  
  <p>Can you also explain the behavior I got from the <code>int</code> variable?</p>