java 方法 示例_Java ArrayDeque peekLast()方法与示例

java 方法 示例

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

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

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

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

    peekLast()方法用于返回此双端队列表示的队列的最后一个元素,但不删除该元素。

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

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

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

    peekLast()方法在检索此双端队列的最后一个元素时不会引发异常。

Syntax:

句法:

    public T peekLast();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of T peekLast() method of ArrayDeque 

import java.util.*;

public class PeekLastOfArrayDeque {
    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: ");
        System.out.println("ArrayDeque Elements = " + d_queue);

        System.out.println();

        // By using peekLast() method to return the
        // element at the last position in ArrayDeque
        String ele = d_queue.peekLast();

        // Display Returned Elements
        System.out.println("d_queue.peekLast() : " + ele);
    }
}

Output

输出量

d_queue: 
ArrayDeque Elements = [C, C++, Java, Php, DotNet]

d_queue.peekLast() : DotNet


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

java 方法 示例

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Data Structures Succinctly Part 1 Table of Contents The Story behind the Succinctly Series of Books ................................................................................... 9 Chapter 1 Algorithms and Data Structures ........................................................................................... 11 Why Do We Care? ................................................................................................................................. 11 Asymptotic Analysis ............................................................................................................................... 11 Rate of Growth ..................................................................................................................................... 11 Best, Average, and Worst Case .......................................................................................................... 13 What are we Measuring? ..................................................................................................................... 13 Code Samples ..................................................................................................................................... 13 Chapter 2 Linked List ............................................................................................................................... 14 Overview ................................................................................................................................................ 14 Implementing a LinkedList Class ........................................................................................................... 16 The Node ............................................................................................................................................. 16 The LinkedList Class ........................................................................................................................... 18 Add ....................................................................................................................................................... 19 Remove ................................................................................................................................................ 20 Contains ............................................................................................................................................... 22 GetEnumerator .................................................................................................................................... 23 Clear .................................................................................................................................................... 24 CopyTo ................................................................................................................................................ 24 Count ................................................................................................................................................... 25 IsReadOnly .......................................................................................................................................... 25 Doubly Linked List .................................................................................................................................. 25 Node Class .......................................................................................................................................... 26 Add ....................................................................................................................................................... 26 5 Remove ................................................................................................................................................ 28 But Why? ............................................................................................................................................. 31 Chapter 3 Array List ................................................................................................................................. 33 Overview ................................................................................................................................................ 33 Class Definition ...................................................................................................................................... 33 Insertion ................................................................................................................................................. 35 Growing the Array ................................................................................................................................ 35 Insert .................................................................................................................................................... 37 Add ....................................................................................................................................................... 38 Deletion .................................................................................................................................................. 39 RemoveAt ............................................................................................................................................ 39 Remove ................................................................................................................................................ 40 Indexing.................................................................................................................................................. 40 IndexOf ................................................................................................................................................ 40 Item ...................................................................................................................................................... 41 Contains ............................................................................................................................................... 42 Enumeration ........................................................................................................................................... 42 GetEnumerator .................................................................................................................................... 42 Remaining IList<T> Methods ................................................................................................................. 43 Clear .................................................................................................................................................... 43 CopyTo ................................................................................................................................................ 43 Count ................................................................................................................................................... 43 IsReadOnly .......................................................................................................................................... 44 Chapter 4 Stack and Queue .................................................................................................................... 45 Overview ................................................................................................................................................ 45 Stack ...................................................................................................................................................... 45 6 Class Definition .................................................................................................................................... 46 Push ..................................................................................................................................................... 47 Pop ....................................................................................................................................................... 47 Peek ..................................................................................................................................................... 48 Count ................................................................................................................................................... 48 Example: RPN Calculator .................................................................................................................... 49 Queue .................................................................................................................................................... 51 Class Definition .................................................................................................................................... 51 Enqueue ............................................................................................................................................... 52 Dequeue .............................................................................................................................................. 52 Peek ..................................................................................................................................................... 53 Count ................................................................................................................................................... 53 Deque (Double-Ended Queue) .............................................................................................................. 53 Class Definition .................................................................................................................................... 54 Enqueue ............................................................................................................................................... 55 Dequeue .............................................................................................................................................. 55 PeekFirst .............................................................................................................................................. 56 PeekLast .............................................................................................................................................. 57 Count ................................................................................................................................................... 57 Example: Implementing a Stack .......................................................................................................... 58 Array Backing Store ............................................................................................................................. 59 Class Definition .................................................................................................................................... 62 Enqueue ............................................................................................................................................... 62 Dequeue .............................................................................................................................................. 65 PeekFirst .............................................................................................................................................. 66 PeekLast .............................................................................................................................................. 66 Count ................................................................................................................................................... 67 7 Chapter 5 Binary Search Tree ................................................................................................................. 68 Tree Overview ........................................................................................................................................ 68 Binary Search Tree Overview ................................................................................................................ 69 The Node Class ..................................................................................................................................... 70 The Binary Search Tree Class ............................................................................................................... 71 Add ....................................................................................................................................................... 72 Remove ................................................................................................................................................ 74 Contains ............................................................................................................................................... 79 Count ................................................................................................................................................... 81 Clear .................................................................................................................................................... 81 Traversals .............................................................................................................................................. 82 Preorder ............................................................................................................................................... 82 Postorder ............................................................................................................................................. 83 Inorder .................................................................................................................................................. 84 GetEnumerator .................................................................................................................................... 86 Chapter 6 Set ............................................................................................................................................ 87 Set Class ................................................................................................................................................ 87 Insertion ................................................................................................................................................. 89 Add ....................................................................................................................................................... 89 AddRange ............................................................................................................................................ 89 Remove .................................................................................................................................................. 90 Contains ................................................................................................................................................. 90 Count ...................................................................................................................................................... 91 GetEnumerator ...................................................................................................................................... 91 Algorithms .............................................................................................................................................. 92 Union .................................................................................................................................................... 92 8 Intersection .......................................................................................................................................... 93 Difference ............................................................................................................................................. 94 Symmetric Difference .......................................................................................................................... 95 IsSubset ............................................................................................................................................... 96 Chapter 7 Sorting Algorithms ................................................................................................................. 98 Swap ...................................................................................................................................................... 98 Bubble Sort ............................................................................................................................................ 98 Insertion Sort ........................................................................................................................................ 100 Selection Sort ....................................................................................................................................... 103 Merge Sort ........................................................................................................................................... 105 Divide and Conquer ........................................................................................................................... 105 Merge Sort ......................................................................................................................................... 106 Quick Sort ............................................................................................................................................ 108

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值