方法pop()在Java中做什么?
的弹出()方法用于在该堆叠的顶部以去除对象,并返回该对象作为该函数的值。
示例
import java.util.*;
public class StackDemo {
public static void main(String args[]) {
Stack st = new Stack();
st.push("Java");
st.push("Source");
st.push("code");
System.out.println("Removed object is: "+st.pop());
System.out.println("Elements after remove: "+st);
}
}输出结果
Removed object is: code Elements after remove: [Java, Source]