日期:2014-05-20 浏览次数:20839 次
public class TestStack { public static void main(String[] args) { Deque<String> st = new ArrayDeque<String>(); int in=1000; int temp=in; while(temp>0){ st.push("1");//这个地方报 java.lang.OutOfMemoryError: Java heap space temp=in/2; } Iterator<String> itr=st.descendingIterator(); while(itr.hasNext()){ System.out.println(itr.next()); } } }
public static void main(String[] args) { Deque<String> st = new ArrayDeque<String>(); int temp = 1000; while (temp > 0) { st.push("1"); temp /= 2; } Iterator<String> itr = st.descendingIterator(); while (itr.hasNext()) { System.out.println(itr.next()); } }
------解决方案--------------------