View Single Post
  #1 (permalink)  
Old 01-28-2008, 02:19 PM
bugger bugger is offline
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Stack not popping
The code below should pop 4 elements, but it just shows 2 elements. I am not able to understand the prolem there:
Code:
Stack stack = new Stack(); stack.push("Obj1"); stack.push("Obj2"); stack.push("Obj3"); stack.push("Obj4"); System.out.println(stack.size()); for(int i=0;i<stack.size();i++) { System.out.println("Stack header is: " + stack.peek()); System.out.println("Popped value is: " + stack.pop()); }
Output:

Code:
Stack header is: Obj4 Popped value is: Obj4 Stack header is: Obj3 Popped value is: Obj3
Reply With Quote
Sponsored Links