展开全部

s.peek() 表示的是查看堆栈顶部的对象,但不从堆栈中移除它。

除此之外:e69da5e887aa62616964757a686964616f31333337623430

push(E item) 表示的是把项压入堆栈顶部。

pop() 表示的是移除堆栈顶部的对象,并作为此函数的值返回该对象。

empty() 表示的是测试堆栈是否为空。

search(Object o) 表示的是返回对象在堆栈中的位置,以 1 为基数。

以下是从jdk中拿下来的相关方法的源码,可以参看下:public class Stack extends Vector {

/**

* Creates an empty Stack.

*/

public Stack() {

}

/**

* Pushes an item onto the top of this stack. This has exactly

* the same effect as:

*

* addElement(item)

*

* @param   item   the item to be pushed onto this stack.

* @return  the item argument.

* @see     java.util.Vector#addElement

*/

public E push(E item) {

addElement(item);

return item;

}

/**

* Removes the object at the top of this stack and returns that

* object as the value of this function.

*

* @return     The object at the top of this stack (the last item

*             of the Vector object).

* @exception  EmptyStackException  if this stack is empty.

*/

public synchronized E pop() {

Eobj;

intlen = size();

obj = peek();

removeElementAt(len - 1);

return obj;

}

/**

* Looks at the object at the top of this stack without removing it

* from the stack.

*

* @return     the object at the top of this stack (the last item

*             of the Vector object).

* @exception  EmptyStackException  if this stack is empty.

*/

public synchronized E peek() {

intlen = size();

if (len == 0)

throw new EmptyStackException();

return elementAt(len - 1);

}

/**

* Tests if this stack is empty.

*

* @return  true if and only if this stack contains

*          no items; false otherwise.

*/

public boolean empty() {

return size() == 0;

}

/**

* Returns the 1-based position where an object is on this stack.

* If the object o occurs as an item in this stack, this

* method returns the distance from the top of the stack of the

* occurrence nearest the top of the stack; the topmost item on the

* stack is considered to be at distance 1. The equals

* method is used to compare o to the

* items in this stack.

*

* @param   o   the desired object.

* @return  the 1-based position from the top of the stack where

*          the object is located; the return value -1

*          indicates that the object is not on the stack.

*/

public synchronized int search(Object o) {

int i = lastIndexOf(o);

if (i >= 0) {

return size() - i;

}

return -1;

}

/** use serialVersionUID from JDK 1.0.2 for interoperability */

private static final long serialVersionUID = 1224463164541339165L;

}

java peek函数_java (String) s.peek()是什么意思?相关推荐

  1. java lambda函数_Java SE 8新功能介绍:使用Lambda Expression进行函数式编程

    java lambda函数 " Java SE 8新功能浏览 "系列的这篇文章将深入了解Lambda表达式 . 我将向您展示Lambda表达式的几种不同用法. 它们都具有功能接口的 ...

  2. java 字符串函数_Java字符串函数– 25+必须知道方法

    java 字符串函数 Java字符串函数 (Java String Functions) Java String class has a lot of functions to manipulate ...

  3. java main函数_Java经典面试题集锦

    主题1:关于Java main方法的核心面试问题 1.如果main方法被声明为私有,会发生什么? 2.如果不提供String数组作为main方法的参数,会发生什么? 3.我们可以重载main()方法吗 ...

  4. java 虚函数_Java的虚方法

    虚方法出现在Java的多态特性中, 父类与子类之间的多态性,对父类的函数进行重新定义.如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding).在Java中,子类 ...

  5. java日期函数_JAVA 日期、时间函数大全(超全)

    实 习期间使用ExtJs做项目的时候需要获取上下班时间并进行上网访问记录的截取和判断,需要处理时间以及字符串与时间之间的转换.本想自作一篇关于时间的 博文,但发现java时间函数方式多变,不如上网查资 ...

  6. java虚拟函数_java实现多态中的虚函数相关概念

    本文转载自参考博客 1. Java虚函数 虚函数的存在是为了多态. C++中普通成员函数加上virtual关键字就成为虚函数 Java中其实没有虚函数的概念,它的普通函数就相当于C++的虚函数,动态绑 ...

  7. java peek函数_Java 8 Stream Api 中的 peek 操作

    1. 前言 我在 Java 8 Stream API中的 map 和flatMap 中讲述了Java8 Stream API中 map 操作和 flatMap 操作的区别.然后有小伙伴告诉我 peek ...

  8. java replaceall函数_JAVA中string.replace和string.replaceAll的区别及用法

    展开全部 JAVA中string.replace()和string.replaceAll()的区别及用法乍一看,字面上理解好像replace只替换第一个出现的字符(受javascript的影响),32 ...

  9. java replaceall函数_java基础—-String中replace和replaceAll方法

    这里面我们分析一下replace与replaceAll方法的差异以及原理. replace各个方法的定义 一.replaceFirst方法 public String replaceFirst(Str ...

最新文章

  1. 二叉树:二叉搜索树的创建和插入
  2. C++之头文件与源文件
  3. 逐行计算、逐行递延、逐行更新
  4. A single input file is required for a non-link phase when an outputfile is specified
  5. 【翻译】(5)Android.mk File
  6. 炼丹面试官的面试笔记
  7. hadoop 2.4.1 集群安装二
  8. python下载微信公众号文章_python如何导出微信公众号文章方法详解
  9. 【渝粤题库】陕西师范大学164212 国际贸易实务 作业(专升本)
  10. 4、Kafka常见问题
  11. Java 集成开发环境 Eclipse 安装
  12. linux虚拟机的密钥,Linux虚拟机之间实现密钥登陆
  13. EXCEL VBA编程(excel办公高手必经之路)-曾贤志-专题视频课程
  14. 25个常用的正则表达式汇总
  15. Linux系统、Ubuntu更换清华软件源
  16. 360浏览器下载|360安全浏览器下载
  17. 项目配置多Redis数据源(Redis分片)
  18. 无锡高二计算机会考内容,无锡期中考试卷分析,看一看高一高二高三数学都考了哪些...
  19. mysql入门_高洛峰_简介_linux安装_远程连接配置_sql语句初始
  20. 【WLAN】【测试】WLAN相关测试软件一览

热门文章

  1. C++ 使用Poco库操作 json 文件
  2. 各大应用商店APP上架指南
  3. python 拉丁超立方抽样
  4. 3.Navicat Premium:导入excel文件
  5. 砸盘、销号、解散社群,Merlin Lab“跑路三连”暴露了DeFi哪些问题?
  6. Java程序员掉发系列——程序员的成长之路
  7. MAC恢复出厂设置(官方教程)
  8. 联想G40-30进入PE鼠标键盘失灵解决方法
  9. 基于json文件创建后端模拟接口
  10. 【Arcpy】批量合并重叠拓扑