Java PriorityQueue size() 方法

2024 年 11 月 9 日 | 阅读 2 分钟

PriorityQueue 类的 size() 方法返回此集合中包含的元素数量。如果此集合中的元素数量超过 Integer.MAX_VALUE,则该方法返回 Integer.MAX_VALUE

语法

参数

不适用

指定者:

PriorityQueue 类的 size() 方法由以下部分定义:

  • Collection<E> 接口中的 size() 方法。
  • AbstractCollection<E> 接口中的 size() 方法。

返回值

size() 方法返回此集合中包含的元素计数。

示例 1

输出

First PriorityQueueis : [123, 375, 258, 682, 842, 654, 556, 998]
The size of first queue is: 8
Second PriorityQueueis : [Gaurav, Hitesh]
The size of second queue is: 2

示例 2

输出

The strength of Btech_Cse is 5

示例 3

输出

2 elements = [Himanshu, Rinku]
0 elements = []