java peek方法_Java ArrayDeque peek()方法与示例
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()方法是一個非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
peek() Method does not throw an exception at the time retrieving the head element of this deque.
peek()方法在檢索此雙端隊列的head元素時不會引發(fā)異常。
Syntax:
句法:
public T peek();Parameter(s):
參數(shù):
It does not accept any parameter.
它不接受任何參數(shù)。
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 elementsDeque < String > d_queue = new ArrayDeque < String > (10);// By using add() method to add elements// in ArrayDequed_queue.add("C");d_queue.add("C++");d_queue.add("Java");d_queue.add("Php");d_queue.add("DotNet");// Display Deque ElementsSystem.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 ArrayDequeString ele = d_queue.peek();// Display Returned ElementsSystem.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方法
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的java peek方法_Java ArrayDeque peek()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: element 项目 示例_Java A
- 下一篇: 离散数学和组合数学什么关系_关系类型|