Java PriorityQueue size() Method

The size() method of PriorityQueue class returns the number of elements contained by this collection. If there are more than Integer.MAX_VALUE elements in this collection, the method returns Integer.MAX_VALUE.

Syntax

Parameter

NA

Specified By

The size() method of PriorityQueue class is specified by:

  • size() method in interface Collection<E>.
  • size() method in interface AbstractCollection<E>.

Return Value

The size() method returns the count of elements contained by this collection.

Example 1

Output:

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

Example 2

Output:

The strength of Btech_Cse is 5

Example 3

Output:

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