Javatpoint Logo
Javatpoint Logo

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

Test it Now

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

Test it Now

Output:

The strength of Btech_Cse is 5

Example 3

Test it Now

Output:

2 elements = [Himanshu, Rinku]
0 elements = []
Next TopicJava PriorityQueue



Help Others, Please Share

facebook twitter pinterest