Java PriorityQueue poll()方法與示例

PriorityQueue類poll()方法 (PriorityQueue Class poll() method)

  • poll() method is available in java.util package.

    poll()方法在java.util包中可用。

  • poll() method is used to return the first element with removing an element from this PriorityQueue.

    poll()方法用于返回第一個元素,并從此PriorityQueue中刪除一個元素。

  • poll() 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.

    poll()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • poll() method does not throw an exception at the time of returning an element.

    poll()方法在返回元素時不會引發異常。

Syntax:

句法:

    public Element poll();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is Element, it returns the head element from this PriorityQueue when exists otherwise it returns null.

方法的返回類型為Element ,如果存在,它將從此PriorityQueue返回head元素,否則返回null。

Example:

例:

// Java program to demonstrate the example 
// of Element poll() method of 
// PriorityQueue
import java.util.*;
public class PollOfPriorityQueue {
public static void main(String args[]) {
// Instantiate PriorityQueue
PriorityQueue < String > pq = new PriorityQueue < String > ();
// By using add() method is add
// the given element into priority
// queue
pq.add("C");
pq.add("C++");
pq.add("JAVA");
pq.add("PHP");
pq.add("ANDROID");
// Display PriorityQueue
System.out.println("PriorityQueue: " + pq);
// By using poll() method is to
// return and remove the first element
// from this PriorityQueue
Object ele = pq.poll();
// Display poll element
System.out.println("pq.poll(): " + ele);
// Display PriorityQueue
System.out.println("PriorityQueue: " + pq);
}
}

Output

輸出量

PriorityQueue: [ANDROID, C, JAVA, PHP, C++]
pq.poll(): ANDROID
PriorityQueue: [C, C++, JAVA, PHP]

翻譯自: https://www.includehelp.com/java/priorityqueue-poll-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541424.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541424.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541424.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

scrapy抓取淘寶女郎

scrapy抓取淘寶女郎 準備工作 首先在淘寶女郎的首頁這里查看&#xff0c;當然想要爬取更多的話&#xff0c;當然這里要查看翻頁的url,不過這操蛋的地方就是這里的翻頁是使用javascript加載的&#xff0c;這個就有點尷尬了&#xff0c;找了好久沒有找到&#xff0c;這里如果有朋…

map在Java集合_java集合之Map

MapMap用于保存具有映射關系的數據。Map中key不允許重復&#xff0c;value可以重復&#xff0c;key和value之間存在單向一對一關系HashMap和Hashtable區別1 Hashtable線程安全、HashMap線程不安全&#xff0c;所以HashMap性能高一點2 Hashtable不允許用null做key和value&#x…

Java OutputStream close()方法與示例

OutputStream類close()方法 (OutputStream Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this OutputStream stream and free all system resources linked with this stream and …

怎樣在fastboot 里面加入新的命令

fastboot 是android 默認的一種debug 方法。它的優點是在進入linux kernel 之前就可以操作。默認fastboot 支持的命令&#xff1a; usage: fastboot [ <option> ] <command>commands: update <filename> reflash device …

java編寫字符串連接程序注釋_Java 注解自動化處理對應關系實現注釋代碼化

public class EsQuery { private static int DEFAULT_SIZE 100; private final Map termFilter;private final Map rangeFilter;private final Map matchFilter;private int size;private String orderBy null;private String order null; // query 查詢語法, 是否需要 filtere…

getlanguage_Java語言環境getLanguage()方法與示例

getlanguage區域設置類getLanguage()方法 (Locale Class getLanguage() method) getLanguage() method is available in java.util package. getLanguage()方法在java.util包中可用。 getLanguage() method is used to retrieve this Locale language code and the language co…

[轉]Anaconda

安裝 Anaconda Anaconda 可用于 Windows、Mac OS X 和 Linux。可以在 https://www.continuum.io/down... 上找到安裝程序和安裝說明。 如果計算機上已經安裝了 Python&#xff0c;這不會有任何影響。實際上&#xff0c;腳本和程序使用的默認 Python 是 Anaconda 附帶的 Python。…

win10 iot core java_Windows 10 IoT Core 正式版初體驗

今天收到Windows 10 IoT Core Team郵件&#xff0c;Windows 10 IoT Core正式發布。以下記錄了今天在Raspberry Pi 2上的體驗過程&#xff1a;準備工作一臺運行著正版Windows 10且版本不小于10240的個人PCVisual Studio 2015 版本不小于14.0.23107.0 D14Rel Install Visual Stud…

filterwriter_Java FilterWriter flush()方法與示例

filterwriterFilterWriter類flush()方法 (FilterWriter Class flush() method) flush() method is available in java.io package. flush()方法在java.io包中可用。 flush() method is used to flush out the string from this FilterWriter stream. flush()方法用于從此Filter…

VUE2 第五天學習--過渡效果

閱讀目錄 1.理解VUE---過渡效果回到頂部1.理解VUE---過渡效果 1. 過渡的-css-類名會有4個(css) 類名在 enter/leave 在過渡中切換。1. v-enter: 進入過渡的開始狀態。在元素被插入時生效&#xff0c;在下一個幀移除。2. v-enter-active: 進入過渡的結束狀態。在元素被插入時生效…

java 集合addall_Java集合的addAll()方法和示例

java 集合addall集合類的addAll()方法 (Collections Class addAll() method) addAll() Method is available in java.lang package. addAll()方法在java.lang包中可用。 addAll() Method is used to put all the given elements(ele) to the given collection (co). addAll()方…

國家可持續發展議程創新示范區創建工作推進會在北京召開

2019獨角獸企業重金招聘Python工程師標準>>> 為推進地方申報國家可持續發展議程創新示范區相關工作&#xff0c;根據國家可持續發展議程創新示范區創建工作的進展及需求&#xff0c;2017年4月23日—25日&#xff0c;科技部社會發展科技司、中國21世紀議程管理中心在…

java控制臺打印圖片_java——控制臺輸入打印圖形

1. 打印直角三角形需求說明&#xff1a;從控制臺輸入直角三角形的高度(行數)。每行*的數目依次為1、3、5、7等。實現思路&#xff1a;外層循環控制行數&#xff0c;根據用戶輸入的行數得到外層循環條件分析每行打印的內容&#xff1a;每一行均打印*號&#xff0c;第i行的*號數為…

Java日歷compareTo()方法與示例

日歷類的compareTo()方法 (Calendar Class compareTo() method) compareTo() method is available in java.util package. compareTo()方法在java.util包中可用。 compareTo() method is used to compare two Calendar objects or in other words, we can say this method is u…

在struts2中配置自定義攔截器放行多個方法

源碼&#xff1a; 自定義的攔截器類&#xff1a; //自定義攔截器類:LoginInterceptor ; package com.java.action.interceptor; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionInvocation;im…

java多態和泛型_Java面向對象(二) 接口、多態和泛型

一、接口二、多態多態是同一個行為具有多個不同表現形式或形態的能力。2.1 類型轉換轉換方式隱式 向上轉型對于基本數據類型&#xff0c;存儲容量低的可自動向存儲容量高的類型轉換對于引用變量&#xff0c;子類可被轉換為超類&#xff0c;可被賦給所屬類實現的接口的引用顯式 …

Java ArrayList contains()方法及示例

ArrayList類contains()方法 (ArrayList Class contains() method) contains() method is available in java.util package. contains()方法在java.util包中可用。 contains() method is used to check whether this Arraylist contains the given object or not. contains()方法…

BlockingQueue詳解

前言&#xff1a; 在新增的Concurrent包中&#xff0c;BlockingQueue很好的解決了多線程中&#xff0c;如何高效安全“傳輸”數據的問題。通過這些高效并且線程安全的隊列類&#xff0c;為我們快速搭建高質量的多線程程序帶來極大的便利。本文詳細介紹了BlockingQueue家庭中的所…

java isempty_Java ArrayDeque isEmpty()方法與示例

java isemptyArrayDeque類isEmpty()方法 (ArrayDeque Class isEmpty() method) isEmpty() Method is available in java.lang package. isEmpty()方法在java.lang包中可用。 isEmpty() Method is used to check whether this deque is "empty" or "non-empty&qu…

[QGLViewer]3D場景鼠標點擊位置

重載鼠標事件&#xff1a; void AxMapControl::mousePressEvent(QMouseEvent* e) {switch(currentTool){case AX_DRAW_DIRECTION:{if (e->button() Qt::LeftButton) {QPoint screenPte->pos();qglviewer::Vec orig1, dir1;camera()->convertClickToLine(screenPt, or…