Java Deque contains() 方法

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

Java Deque 接口的 contains() 方法在 deque 包含指定元素时返回 true。

指定者

  • Collection<E> 接口中的 contains

语法

参数

上述方法只有一个参数

  1. a.) 元素 'o',该元素已存在于 deque 中并被测试。

返回

上述方法返回一个布尔值,即如果指定元素已存在于 deque 中,则为 true。

Throw

ClassCastException - 如果给定元素的类与 deque 不兼容。

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

示例 1

输出

The list of the elements is given as : 
The final result of the deque is given as : [45.0, 31.0, 456.0, 29.0]
The first element is in the list.
The second element is not in the list.

示例 2

输出

The list of the elements is given as : 
The final result of the deque is given as : [A, J, M, O]
The first element is not in the list.
The second element is not in the list.

示例 3

输出

The list of vowels is given as : 
[a, e, i, o, u]
The alphabet is not a vowel.
下一主题Java Deque