• Java 数据结构教程

栈中元素的弹出



栈中的弹出操作是指从栈中删除元素。在对栈执行此操作时,将删除栈顶的元素,即最后插入栈的元素将首先弹出。(后进先出)

示例

import java.util.Stack;

public class PoppingElements {
   public static void main(String args[]) {
      Stack stack = new Stack();
      stack.push(455);
      stack.push(555);
      stack.push(655);
      stack.push(755);
      stack.push(855);
      stack.push(955);
      
      System.out.println("Elements of the stack are :"+stack.pop());
      System.out.println("Contents of the stack after popping the element :"+stack);
   }
}

输出

Elements of the stack are :955
Contents of the stack after popping the element :[455, 555, 655, 755, 855]
广告