title: java heap memory usage exception when using FOR lOOP
body: <p>When i run the below program i got the exception when for loop begins its execution at i=1031521. How to over come memory usage of this type?</p>
  
  <pre><code>class wwww
      {
          public static void main(String args[])
          {
              String abc[]=new String[4194304];
              String wwf="";
              int s_count=524286;
              for(int i=0;i&lt;4194304;i++)
              {
                  System.out.println("----------enter--------"+i);
                  abc[i]=""+i;
                  System.out.println("----------exit--------"+i);
              }
          }
      }
  </code></pre>
  
  <p>The exception is:</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Arrays.java:2882)
      at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.
  java:100)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390
  )
      at java.lang.StringBuilder.append(StringBuilder.java:119)
      at wwww.main(wwww.java:12)
  </code></pre>