java peek方法

ArrayDeque类peek()方法 (ArrayDeque Class peek() method)

  • peek() Method is available in java.lang package.

    peek()方法在java.lang包中可用。

  • peek() Method is used to return the head element of the queue denoted by this deque but without removing the element.

    peek()方法用于返回此双端队列表示的队列的头元素,但不删除该元素。

  • peek() Method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    peek()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • peek() Method does not throw an exception at the time retrieving the head element of this deque.

    peek()方法在检索此双端队列的head元素时不会引发异常。

Syntax:

句法:

    public T peek();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is T, it returns the head element denoted by this deque otherwise it returns null when this deque is "blank".

方法的返回类型为T ,它返回此双端队列表示的head元素,否则当此双端队列为“空白”时返回null。

Example:

例:

// Java program to demonstrate the example
// of T peek() method of ArrayDeque
import java.util.*;
public class PeekOfArrayDeque {public static void main(String[] args) {// Creating an ArrayDeque with initial capacity of
// storing elements
Deque < String > d_queue = new ArrayDeque < String > (10);
// By using add() method to add elements
// in ArrayDeque
d_queue.add("C");
d_queue.add("C++");
d_queue.add("Java");
d_queue.add("Php");
d_queue.add("DotNet");
// Display Deque Elements
System.out.println("d_queue before peek(): ");
System.out.println("ArrayDeque Elements = " + d_queue);
System.out.println();
// By using peek() method to return the
// element at the first position in ArrayDeque
String ele = d_queue.peek();
// Display Returned Elements
System.out.println("d_queue.peek() : " + ele);
}
}

Output

输出量

d_queue before peek():
ArrayDeque Elements = [C, C++, Java, Php, DotNet]d_queue.peek() : C

翻译自: https://www.includehelp.com/java/arraydeque-peek-method-with-example.aspx

java peek方法

java peek方法_Java ArrayDeque peek()方法与示例相关推荐

  1. java set 包含_Java Set.contains()方法:判断Set集合是否包含指定的对象

    Java 集合类中的 Set.contains() 方法判断 Set 集合是否包含指定的对象.该方法返回值为 boolean 类型,如果 Set 集合包含指定的对象,则返回 true,否则返回 fal ...

  2. java 发送邮件 菜鸟_Java发送邮件的方法

    1.需要的jar包 2.具体实现方法 1.设置邮箱主机.需要认证.邮箱协议 Properties pro=new Properties(); pro.setProperty("mail.ho ...

  3. java show过时_Java中show() 方法被那个方法代替了? java编程 显示类中信

    你说的show是swing里的吧,在老版本中Component这个超类确实有show这个方法,而且这个方法也相当有用,使一个窗口可见,并放到最前面.在jdk5.0中阻止了这个方法,普遍用setVisi ...

  4. java的scanner的方法_Java Scanner reset()方法

    Java Scanner reset()方法 java.util.Scanner.reset() 方法重置该扫描仪.重设scanner 丢弃所有的这些可能已被useDelimiter(java.uti ...

  5. java方法重载和重载方法_Java 8的方法参考进一步限制了重载

    java方法重载和重载方法 方法重载一直是一个充满喜忧参半的话题. 我们已经在博客上介绍了它,并介绍了几次警告: 您会后悔对Lambdas应用重载! 保持干燥:方法重载 为什么每个人都讨厌操作员超载 ...

  6. java method方法_Java Method.getTypeParameters方法代碼示例

    import java.lang.reflect.Method; //導入方法依賴的package包/類 private void validateRuleMethod(MethodRuleDefin ...

  7. java中断响应时间_Java多线程 sleep方法响应中断 sleep面试问题(与wait/notify的

    Java多线程 sleep方法响应中断 sleep面试问题(与wait/notify的 Java多线程 sleep方法响应中断 & sleep面试问题(与wait/notify的比较) 文章目 ...

  8. java中math的方法_Java Math所有方法

    首页 > 基础教程 > 常用类 > 常用 Number & Math类 Java Math所有方法 Math类包含完成基本数学函数所需的方法.这些方法分为三类:三角函数方法. ...

  9. java中方法_java中的方法

    java中的方法 java作为一种面向对象的语言,具有以下特性:继承.封装.多态.抽象.类.对象.实例.方法和重载. 今天讲解的是java方法的概念. 什么是方法? java方法是语句的集合,他们在一 ...

最新文章

  1. linux那个11命令是什么意思,11个有用的Linux命令
  2. Hadoop文件系统元数据fsimage和编辑日志edits
  3. 结对-五子棋游戏-开发过程
  4. 【BZOJ】3053: The Closest M Points(kdtree)
  5. Mysql索引优化实例讲解
  6. 服务器维护 文档,ERP系统维护服务器维护管理文档.docx
  7. 杨振宁惹谁了?(zz)
  8. #pragma push_macro(new) 及扩展操作
  9. 初中计算机表格知识点,初中信息技术考试知识点.doc
  10. 2020电子设计大赛——坡道行驶小车
  11. build/envsetup.sh 简介
  12. python 打开网页方法_python打开网页的方法
  13. python画立体爱心_Python画爱心
  14. 肖明计算机网络答案,袭肖明
  15. 第九章:项目资源管理-0316
  16. 抖音视频链接数据分析
  17. Codeforces Round #644 (Div. 3) D.Buying Shovels
  18. wi-fi测试软件正确吗,几款Wi-Fi信号测试小工具
  19. catia螺纹孔在二维图上不显示_catia里面螺纹怎么显示不出来呢??哪儿能设置...
  20. python画频率统计图

热门文章

  1. c++中关于初始化型参列表的一些问题
  2. 是什么牌子_水晶项链什么牌子好
  3. java类初始化顺序_《To Be a Better Javaer》-- Java 基础篇 vol.2:面向对象
  4. ant实例 jmeter_Jmeter+ant搭建环境
  5. 俩台电脑怎么设置同一局域网_方法 | 把手机上的照片传到电脑上
  6. Latex 加空格的方法
  7. Springboot 整合 swagger
  8. java并发编程——线程池的工作原理与源码解读
  9. 人工智能能够构建一个自主驱动云吗?
  10. Oracle Linux 6.5 RPM安装Mysql 5.7.11