Java Deque addLast() 方法

2025 年 3 月 22 日 | 阅读需 2 分钟

Java Deque 接口的 addLast() 方法用于在 deque 的末尾插入指定的元素。

语法

参数

上述方法只有一个参数

  1. 需要插入的元素“e”

返回

不适用

Throw

IllegalStateException - 如果由于容量限制,无法在此时添加元素。

ClassCastException - 如果指定元素的类阻止其添加到 deque 中。

NullPointerException - 如果指定元素为 null 且 deque 不允许 null 元素。

IllegalArgumentException - 如果给定元素的某些属性阻止其添加到 deque 中。

示例 1

输出

The elements are adding at the front of the deque : [44, 33, 22, 11]

示例 2

输出

The subjects are given as : [FAT, CAO, JAVA, DBMS]

示例 3

输出

Enter the number of times you want to enter the names : 4
The names are : 
Ashu
Hitesh
Jasmeet
Isha
The final deque is : [Ashu, Hitesh, Jasmeet, Isha]
下一主题Java Deque