博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java offer_Java ArrayDeque offer()方法与示例
阅读量:2531 次
发布时间:2019-05-11

本文共 2312 字,大约阅读时间需要 7 分钟。

java offer

ArrayDeque类的offer()方法 (ArrayDeque Class offer() method)

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

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

  • offer() Method is used to add the given element at the end of the deque.

    offer()方法用于在双端队列的末尾添加给定元素。

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

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

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

    offer()方法可能会在双端队列中添加元素时引发异常。

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

    NullPointerException :当给定元素为null时,可能引发此异常。

Syntax:

句法:

public boolean offer(T element);

Parameter(s):

参数:

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

    T element –表示要在此双端队列的最后插入的元素。

Return value:

返回值:

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

该方法的返回类型是布尔值 ,如果给定元素最后加入到双端队列成功返回true,否则返回false。

Example:

例:

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

Output

输出量

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

翻译自:

java offer

转载地址:http://ozozd.baihongyu.com/

你可能感兴趣的文章
组合模式Composite
查看>>
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>
IOS内存管理
查看>>
middle
查看>>