LinkedList公共对象peek()方法 (LinkedList public Object peek() method)

  • This method is available in package java.util.LinkedList.peek().

    软件包java.util.LinkedList.peek()中提供了此方法。

  • This method is used to retrieve the head element of the linked list without removing the head element.

    此方法用于检索链接列表的head元素,而无需删除head元素。

  • If the list is empty then it will return null.

    如果列表为空,则它将返回null。

Syntax:

句法:

    public Object peek(){
}

Parameter(s):

参数:

In this method, we don’t pass any object as a parameter in the method but it returns the first object from the linked list.

在此方法中,我们不会在该方法中传递任何对象作为参数,但是它将返回链表中的第一个对象。

Return value:

返回值:

The return type of this method is not void that means this method returns head object or element (i.e. It returns the only first element in the list). If the list is empty then it will not give any exception.

该方法的返回类型不是void,这意味着该方法返回头对象或元素(即,它返回列表中唯一的第一个元素)。 如果列表为空,则不会给出任何异常。

Java程序演示LinkedList peek()方法的示例 (Java program to demonstrate example of LinkedList peek() method)

import java.util.LinkedList;
public class LinkList {public static void main(String[] args) {LinkedList list = new LinkedList();
// use add() method to add elements in the list
list.add(10);
list.add(20);
list.add(30);
list.add(40);
list.add(50);
//  Current list Output
System.out.println("The Current list is:" + list);
//  Using peek() method it will retrieve first element
// without removing the element from the list
System.out.println("The First Element In The List is:" + list.peekFirst());
}
}

Output

输出量

D:\Programs>javac LinkList.java
D:\Programs>java LinkList
The Current list is:[10, 20, 30, 40, 50]
The First Element In The List is:10

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

Java LinkedList公共对象peek()方法(带示例)相关推荐

  1. Java LinkedList公共对象pollLast()方法(带示例)

    LinkedList公共对象pollLast()方法 (LinkedList public Object pollLast() method) This method is available in ...

  2. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  3. math的用法在java中的使用,Java Math cbrt() 使用方法及示例

    Java Math cbrt() 使用方法及示例 Java Math cbrt()方法返回指定数字的立方根. cbrt()方法的语法为: Math.cbrt(double num) 注意:cbrt() ...

  4. java arraylist 方法返回值,Java ArrayList get() 使用方法及示例

    Java ArrayList get() 使用方法及示例 Java ArrayList get()方法返回指定位置存在的元素. get()方法的语法为: arraylist.get(int index ...

  5. java中peek是什么意思_Java Stack peek()方法与示例

    堆栈类peek()方法peek()方法在java.util包中可用. peek()方法用于从此Stack中返回顶部元素,并且它不删除就检索元素. peek()方法是一种非静态方法,只能通过类对象访问, ...

  6. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  7. Java Math toIntExact() 使用方法及示例 long转int

    Java Math toIntExact()方法从指定的long参数返回int值. toIntExact()方法的语法为: Math.toIntExact(long value) 注意:toIntEx ...

  8. java readtimeout_Java HttpURLConnection.getReadTimeout方法代码示例

    import java.net.HttpURLConnection; //导入方法依赖的package包/类 /** * 得到响应对象 * * @param urlConnection * @retu ...

  9. java invalidate_Java Component.invalidate方法代码示例

    import java.awt.Component; //导入方法依赖的package包/类 /** Installs the component we will embed to display t ...

最新文章

  1. 解决mysql无法远程登陆问题
  2. c# websocketServer base64乱码
  3. RUP概述与实际应用的例子
  4. java让线程空转_Java锁:悲观/乐观/阻塞/自旋/公平锁/闭锁,锁消除CAS及synchronized的三种锁级别...
  5. ubuntu下mysql编码格式设置_Ubuntu 16.04.1下修改MySQL默认编码
  6. 关于处理百万级大批量数据的mysql运行几个重要点
  7. PTA—念数字(C语言)两种方法
  8. 伯努利分布方差_学计量经济学,你应该知道的六种6个概率分布
  9. asp.net2.0 GridView 导出到 Excel
  10. C++基础教程之指针
  11. 10. zf workflow
  12. 【android-音视频】listview中播放音频,实现音频时长的倒计时,暂停,切换。
  13. 囧从流氓同事的河蟹喜酒归来......
  14. checkbox在ftl文件的使用
  15. 如何开发Alexa Intent skill
  16. Amaze UI貌似挂了。。。附上amaze UI框架的图标
  17. 2022年全球与中国一次性内窥镜市场现状及未来发展趋势
  18. 如何恢复手动删除的微信聊天记录?2个简单高效方法推荐
  19. ArcMap-network analyst
  20. Visio复制的图片在Word中不显示

热门文章

  1. python 教学_「Python基础」一次就装好Python手把手装到好
  2. 一分钟学会python编程_用Python教你一分钟检验出来!不用群发_编程语言_Python课程_Python教程_课课家...
  3. nginx proxy_cache缓存详解
  4. 安装python3.9
  5. javascript OOP(下)(九)
  6. Hession矩阵与牛顿迭代法
  7. 机器学习相关——协同过滤
  8. window下php5.6-x64-ts可用php_redis.dll文件
  9. python高维数据_t-SNE高维数据可视化(python)
  10. 易语言python1.1模块_易语言之编写模块与引入模块