空的()方法用来测试堆栈是否为或没有。
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("Is stack empty: "+st.empty());
}
}输出结果
Is stack empty: false