arrays - Java do while loop arralyist problem -
i want ask why java heap space triggered when executing "name.add("tom");"?
<%@ page import="java.util.*" %> <% try { arraylist <string> name = new arraylist<string>(); int count= 0; { name.add("tom"); } while ( count < 2); string[] name = name.toarray(new string[name.size()]); %> <script type="text/javascript"> var output=[]; <%int = 0;%> <%while ( < name.length ) { system.out.println(name[i]);%> output[<%=i%>] = []; output[<%=i%>][0] = '<%=name[i]%>'; <% system.out.println("no exception in javascript.");i++;}%> </script> <% } catch (exception error ){system.out.println(error);}%>
notice in code:
int count= 0; { name.add("tom"); } while ( count < 2); you never change value of count anywhere, , loop loop forever. if change code change count somehow (perhaps using for loop count upwards), should go away. jvm running out of heap space adding many copies of tom can collection, exhausting available memory.
Comments
Post a Comment