栈的理解
栈(Stack)是一种受限的线性数据结构,所谓受限是指栈只暴露栈顶和栈底的操作,其底层是由数组实现的。栈的特性是先进后出。
常用方法

注意上面的peek()方法和pop()方法的区别!
实例
import java.util.Stack;
public class StackTest {
public static void main(String[] args) {
Stack<String> stack = new Stack<String>();
System.out.println("now the stack is " + isEmpty(stack));
stack.push("1");
stack.push("2");
stack.push("3");
stack.push("4");
stack.push("5");
System.out.println("now the stack is " + isEmpty(stack));
System.out.println(stack.peek());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.search("2"));
}
public static String isEmpty(Stack<String> stack) {
return stack.empty() ? "empty" : "not empty";
}
}
输出为:
now the stack is not empty
5
5
4
2






![[oeasy]python0074[专业选修]字节序_byte_order_struct_pack_大端序_小端序](https://img-blog.csdnimg.cn/img_convert/ea67207f7506b60167a2e43930710379.jpeg)












