Java Deque addFirst() 方法

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

Java Deque 接口的 addFirst() 方法用于在 deque 的前端插入指定的元素。

语法

参数

上述方法只有一个参数

  1. 需要添加的元素 'e'

返回

不适用

Throw

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

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

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

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

示例 1

输出

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

示例 2

输出

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

示例 3

输出

Enter the number of times you want to enter the names : 4
The names are : 
Sham
Ram
Stuti
Ranajna
The final deque is : [Ranajna, Stuti, Ram, Sham]
下一主题Java Deque