import java.util.Stack;
/**
* Stack 栈
* 1.empty() 测试堆栈是否为空
* 2.peek() 查看堆栈顶部的对象,但不从堆栈中移除它
* 3.pop() 移除堆栈顶部的对象,并作为此函数的值返回该对象。
* 4.push(E item) 把项压入堆栈顶部。
* 5.search(Object o) 返回对象在堆栈中的位置,以 1 为基数。
*/
public class StackTest {
public StackTest()
{
Stack<String> st=new Stack<String>();
st.push("1a");
st.push("2b");
st.push("3c");
st.push("4d");
System.out.println("size is:"+st.size()); //大小
System.out.println("peek is:"+st.peek()); //查看栈顶元素
System.out.println("isEmpty is:"+st.isEmpty()); //判断栈是否为空
System.out.println("toString is:"+st.toString());
System.out.println(st.search("1a")); //判断元素位置
System.out.println("pop is:"+st.pop()); //移除窄元素
}
public static void main(String[] args) {
new StackTest();
}
}
/**
* Stack 栈
* 1.empty() 测试堆栈是否为空
* 2.peek() 查看堆栈顶部的对象,但不从堆栈中移除它
* 3.pop() 移除堆栈顶部的对象,并作为此函数的值返回该对象。
* 4.push(E item) 把项压入堆栈顶部。
* 5.search(Object o) 返回对象在堆栈中的位置,以 1 为基数。
*/
public class StackTest {
public StackTest()
{
Stack<String> st=new Stack<String>();
st.push("1a");
st.push("2b");
st.push("3c");
st.push("4d");
System.out.println("size is:"+st.size()); //大小
System.out.println("peek is:"+st.peek()); //查看栈顶元素
System.out.println("isEmpty is:"+st.isEmpty()); //判断栈是否为空
System.out.println("toString is:"+st.toString());
System.out.println(st.search("1a")); //判断元素位置
System.out.println("pop is:"+st.pop()); //移除窄元素
}
public static void main(String[] args) {
new StackTest();
}
}