Source of 5.4.java


  1: StackInterface<String> stringStack = new OurStack<>();
  2: stringStack.push("Jim");
  3: stringStack.push("Jess");
  4: stringStack.push("Jill");
  5: stringStack.push("Jane");
  6: stringStack.push("Joe");
  7: 
  8: String top = stringStack.peek(); // Returns "Joe"
  9: System.out.println(top + " is at the top of the stack.");
 10: 
 11: top = stringStack.pop();         // Removes and returns "Joe"
 12: System.out.println(top + " is removed from the stack.");
 13: 
 14: top = stringStack.peek();        // Returns "Jane"
 15: System.out.println(top + " is at the top of the stack.");
 16: 
 17: top = stringStack.pop();         // Removes and returns "Jane"
 18: System.out.println(top + " is removed from the stack.");