title: Java do while loop arralyist problem
body: <p>I want ask why Java heap space is triggered when executing "<code>NAME.add("Tom");</code>"?</p>
  
  <pre><code>&lt;%@ page import="java.util.*" %&gt;
  
  &lt;%
  try {
      ArrayList &lt;String&gt; NAME = new ArrayList&lt;String&gt;();
      int count= 0;
  
      do
      {
          NAME.add("Tom");
      } while ( count &lt; 2);
  
      String[] name = NAME.toArray(new String[NAME.size()]);
  
  %&gt;
  
  &lt;script type="text/javascript"&gt;
      var output=[];
      &lt;%int i = 0;%&gt;
  
      &lt;%while ( i &lt; name.length ) { System.out.println(name[i]);%&gt;
          output[&lt;%=i%&gt;] = [];
          output[&lt;%=i%&gt;][0] = '&lt;%=name[i]%&gt;';
  
      &lt;% System.out.println("No exception in JAVASCRIPT.");i++;}%&gt;
  &lt;/script&gt;
  
  &lt;%
  } catch (Exception error ){System.out.println(error);}%&gt;
  </code></pre>