java (String) s.peek()是什么意思?
来源:百度知道 编辑:UC知道 时间:2024/05/22 05:19:11
与pop()有什么区别?谢谢!
s.peek() 表示的是查看堆栈顶部的对象,但不从堆栈中移除它。
除此之外:
push(E item) 表示的是把项压入堆栈顶部。
pop() 表示的是移除堆栈顶部的对象,并作为此函数的值返回该对象。
empty() 表示的是测试堆栈是否为空。
search(Object o) 表示的是返回对象在堆栈中的位置,以 1 为基数。
以下是从jdk中拿下来的相关方法的源码,可以参看下:
public class Stack<E> extends Vector<E> {
/**
* Creates an empty Stack.
*/
public Stack() {
}
/**
* Pushes an item onto the top of this stack. This has exactly
* the same effect as:
* <blockquote><pre>
* addElemen