java使用栈
开始想直接new Stack<>(); 然后顺手点开了源码
Stack源码:
public class Stack<E> extends Vector<E> {
//构造略
public E push(E item);
public synchronized E pop();
public synchronized E peek();
public boolean empty();
public synchronized int search(Object o);
}
stack文档:
The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top.
When a stack is first created, it contains no items.
A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example:
Deque
翻译成人话:
Stack类是一个后进先出(LIFO)堆栈。它用五个方法扩展了类Vector,使之成为堆栈。
提供了:push,pop,查看栈顶的方法,是否为空的方法,搜索项并发现其离顶部有多远的方法。
第一次声明为空
Deque接口及其实现提供了一组更完整、更一致的LIFO堆栈操作,应该优先使用此类。例如:
Deque
cao 一键白学
看Deque吧
Deque接口
双端队列deque
这玩意啥啥都能干呢。。。
当做堆栈用的时候,就仨方法有用
Stack Method Equivalent Deque Method等效Deque法
push(e) addFirst(e)
pop() removeFirst()
peek() getFirst()
本文来自博客园,作者:荧惑微光,转载请注明原文链接:https://www.cnblogs.com/yinghuoweiguang/p/16083898.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!