public class Demo { private Object[] data; private int top; private int size; public void InitStack(){ size=10; data=new Object[size]; top=0; } public void push(Object o){ if(top==size){ Object[] newdata=new Object[size*2]; for(int i=0;i!=data.length;++i){ newdata[i]=data[i]; } data=newdata; size*=2; } data[top++]=o; } public Object pop(){ if(top==0){ System.out.println("Stack is empty!"); return null; } return data[--top]; } public Object peek(){ if(top==0){ System.out.println("Stack is empty"); return null; } return data[top-1]; } public static void main(String[] args){ Demo demo=new Demo(); demo.InitStack(); for(int i=0;i!=100;++i){ demo.push(i); } int j=(Integer)demo.pop(); System.out.println(j); } }