java 方法 示例_Java ArrayDeque offerFirst()方法與示例

java 方法 示例

ArrayDeque類offerFirst()方法 (ArrayDeque Class offerFirst() method)

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

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

  • offerFirst() Method is used to add the given element at the front of this deque.

    offerFirst()方法用于將給定元素添加到此雙端隊列的前面。

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

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

  • offerFirst() Method may throw an exception at the time of adding element in the deque.

    offerFirst()方法在雙端隊列中添加元素時可能會引發異常。

    NullPointerException: This exception may throw when the given element is null exists.

    NullPointerException :當給定元素為null時,可能引發此異常。

Syntax:

句法:

    public boolean offerFirst(T element);

Parameter(s):

參數:

  • T element – represents the element to be inserted at the first position of this deque.

    T element –表示要在此雙端隊列的第一個位置插入的元素。

Return value:

返回值:

The return type of the method is boolean, it returns true if the given element is added at the front of this deque successfully, else it returns false.

該方法的返回類型是布爾值 ,如果給定的元素在此雙端隊列的前面添加成功返回true,否則返回false。

Example:

例:

// Java program to demonstrate the example 
// of boolean offerFirst(T element) method of ArrayDeque 
import java.util.*;
public class OfferFirstOfArrayDeque {
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 offerFirst(): ");
System.out.println("ArrayDeque Elements = " + d_queue);
System.out.println();
// By using offerFirst() method to add the
// elements at the first position in ArrayDeque
d_queue.offerFirst("Python");
// Display Deque Elements
System.out.println("d_queue after offerFirst(): ");
System.out.println("d_queue.offerFirst() : "+ d_queue);
}
}

Output

輸出量

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

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

java 方法 示例

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

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

相關文章

平院Python習題

在讀寫文件之前&#xff0c;用于創建文件對象的函數是&#xff08; A &#xff09;。 A&#xff0e; open B&#xff0e; create C&#xff0e; file D&#xff0e;folder 解析&#xff1a; open(file, mode‘r’, buffering-1, encodingNone, errorsNone, newlineNone, close…

搭建srs服務器(rtmp)

搭建srs服務器&#xff08;rtmp&#xff09; 目錄:1、下載srs源碼&#xff08;從碼云上&#xff09;&#xff1a;2、 切換到srs.oschina&#xff1a;3、 這里使用3.0版本&#xff1a;4、 切換到trunk&#xff1a;5、 編譯&#xff1a;6、 啟動&#xff1a;7、查看日志輸出&…

MOSS信息管理策略定制(MOSS custom policies)

MOSS引入了信息管理策略&#xff0c;通過給文檔庫或列表附加一些策略可以實現一些自動化的功能&#xff0c;如自動給文檔打標簽&#xff0c;強制文檔的審核&#xff0c;啟用文檔的過期&#xff0c;甚至可以在用戶打印文檔時插入條形碼。難么&#xff0c;這么好用的功能是怎么實…

2560介紹_炒股高手收益翻10倍,只因妙用這一招2560戰法,看了都不虧了

(本文由公眾號越聲研究(yslc927yj)整理&#xff0c;僅供參考&#xff0c;不構成操作建議。如自行操作&#xff0c;注意倉位控制和風險自負。)選股是每個剛入市的新股民需掌握的技巧&#xff0c;通過資金選股了解資金流向&#xff0c;善用工具輕松選股&#xff0c;同時多留意行業…

二進制搜索樹_將排序的數組轉換為二進制搜索樹

二進制搜索樹Problem statement: 問題陳述&#xff1a; Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 給定一個數組&#xff0c;其中元素按升序排序&#xff0c;請將其轉換為高度平衡的BST。 For this problem, a he…

rtmp協議分析(三次握手)

RTMP詳細分析(Message 消息&#xff0c;Chunk分塊) librtmp分析&#xff08;發送數據包處理&#xff09; librtmp分析&#xff08;接收數據包處理&#xff09; RTMP協議是Real Time Message Protocol(實時信息傳輸協議)的縮寫&#xff0c;它是由Adobe公司提出的一種應 用層的協…

OpenAPI系列: 六、OpenAPI策略分析

一、如何注冊 為什么要注冊&#xff1f;訪問 OpenAPI必須擁有Consumer Key和Consumer Secret。 如何注冊&#xff1f;要獲取Consumer Key及Consumer Secret&#xff0c;需要消費方&#xff08;Consumer&#xff09;向服務提供方申請注冊&#xff0c;服務提供方審核通過后會向消…

壓縮、解壓 解決 客戶端查詢大批量數據時等待時間過長的問題

在項目中查詢時&#xff0c;因數據量大&#xff0c;導致網絡傳輸很慢&#xff0c;這就需要在服務器端查詢出的數據進行壓縮處理&#xff0c;后傳輸完了在客戶端進行解壓處理&#xff08;此為在Silverlight中壓縮與解壓&#xff09;&#xff1b; 具體方法如下&#xff1a; using…

C---已知正整數n是兩個不同的質數的乘積,試求出較大的那個質數。

已知正整數n是兩個不同的質數的乘積&#xff0c;試求出較大的那個質數。 思路&#xff1a;由題意可知&#xff0c;n為兩個質數之積&#xff0c;也就是說只要找到一個數能夠被n整除&#xff0c;這個數一定是質數&#xff01;&#xff01;&#xff01;2為最小的質數&#xff0c;…

isnumeric_Python字符串| isnumeric()方法與示例

isnumericisnumeric() is an in-built method in Python, which is used to check whether a string contains only numeric values or not. isnumeric()是Python中的內置方法&#xff0c;用于檢查字符串是否僅包含數字值。 Numeric contain all decimal characters and the f…

合并文件夾中子目錄_01 Linux之統計文件夾中文件個數以及目錄個數

案例分析&#xff1a;今天遇到了一個需要統計路徑下目錄個數的問題如果一個一個的去數會很麻煩&#xff0c;找到了一篇文章剛好提到這個&#xff0c;于是我將方法整理了一下。該方法的鏈接&#xff1a;Linux統計文件夾中文件個數以及目錄個數_SG匚hang的博客-CSDN博客_linux統計…

關于Makefile,Makefile.in,Makefile.am,Configure功能及相互關系的問題

目錄makefile寫法1. 簡介2. 上路之前3. 一個簡單的例子4.說明&#xff1a;4.1、autoscan4.2、 configure.scan4.3、aclocal4.4、autoconf4.5、Makefile.am4.6、 automake4.7、Makefilemakefile寫法 在 Unix 上寫程式的人大概都碰過 Makefile&#xff0c;尤其是用 C 來開發程式…

修改主鍵的SQL

declare defname varchar(100)declare cmd varchar(500)declare tablename varchar(100)declare keyname varchar(100) Set tablenameTemp1Set keynameid --需要設置的key,分隔 select defname name FROM sysobjects so JOIN sysconstraints sc ON so.id sc.constid …

西安理工大學863(轉載)

原創&#xff1a;https://blog.csdn.net/mzj15101229871/article/details/107613162 &#xff08;博主總結的很完整&#xff0c;很厲害&#xff0c;本人為了查看方便&#xff0c;才轉載的。本人只是個小白~&#xff09; 第一章 緒論 考試大綱 1&#xff09;了解數據元素、數…

原理簡介_消息通信的利器MQTT協議簡介及協議原理

- 沒用過但是必須得知道系列 -前言&#xff1a;相比于 XMPP&#xff0c; MQTT 的簡單輕量受到了不少工程師的喜愛&#xff0c;從物聯網到傳統的消息服務&#xff0c;簡單可依賴的 MQTT 到底為何讓人如此著迷呢&#xff1f;MQTT 協議&#xff0d;MQTT 協議簡介及協議原理MQTT(Me…

stl vector 函數_vector :: pop_back()函數以及C ++ STL中的示例

stl vector 函數C vector :: pop_back()函數 (C vector::pop_back() function) vector::pop_back() is a library function of "vector" header, it is used to deletes an element from the end of the vector, it deletes the element from the back and returns …

rtmp協議分析(Message 消息,Chunk分塊)

RTMP詳細分析&#xff08;三次握手&#xff09; librtmp分析&#xff08;發送數據包處理&#xff09; librtmp分析&#xff08;接收數據包處理&#xff09; 目錄1、Message(消息)2、Chunking(Message 分塊)2.1、 Basic Header(基本的頭信息)2.1.1、Basic Header為1個字節時2.1.…

【文摘】 雪念——作者:藍色妖姬

引用原文地址&#xff1a;點我 我本是惆悵之人&#xff0c;擁有不了所謂的快樂&#xff0c;筆尖譜寫不出唯美的風花雪月&#xff0c;只是流露這淡淡的疼痛&#xff0c;淡淡的哀傷。——藍色妖姬。 喜歡雪&#xff0c;喜歡佇立在雪地里&#xff0c;凝視著片片雪花從眼前飄落。 心…

將Sharepoint Server 2010部署到WINDOWS 7

首先祝CNBLOGS上的筒子們新年快樂。Sharepoint 2010 BETA版發布已經有段時間了&#xff0c;總是感覺MS的步伐要比我們這些追逐他的人快很多&#xff0c;不過確實他的每一次革新總給我們帶來了驚喜。 前幾天報名參加了SHAREPOINT 2010 DAY 活動(詳情)&#xff0c;等待著1月16日體…

嵌入式實訓-day1

完全復制一個文件的內容到另外一個文件 思路解析&#xff1a; 首先我這里使用了三個.c文件&#xff0c;分別是&#xff1a;yanyu.c、yanyu_old.c、yanyu_now.c 其中yanyu.c負責將yanyu_old.c中的內容讀入到buff緩沖區中&#xff0c;然后再從buff緩沖區中將數據寫入到yanyu_no…