Javatpoint Logo
Javatpoint Logo

Java ConcurrentLinkedQueue toArray() Method

The toArray() method of ConcurrentLinkedQueue class returns an array containing all the elements present in the queue in no particular order.



  1. NA
  2. a ? this is the array in which the elements of the queue will be stored.

Type Parameters:

T ? this is the component type of the array to hold the collection.

Specified By:

The toArray() method of ConcurrentLinkedQueue class is specified by :

toArray() method in interface Collection<E>.


The toArray() method of ConcurrentLinkedQueue class is overridden by :

toArray() method in class AbstractCollection<E>.

Return Value:

The toArray() method returns an array that contains all the elements of this queue.


The toArray() method throws NullPointerException if the specified array is null.

Example 1

Test it Now


Element  1: Reema
Element  2: Rahul
Element  3: Rita
Element  4: Ramesh

Example 2

Test it Now


Error:(22, 25) java: bad operand types for binary operator '>'
  first type:  java.lang.Object
  second type: java.lang.Object

Operator '<' cannot be applied to java.lang.Object. If we do so, it will give you an error.

This example is the solution to the above described program.

Example 3

Test it Now


Elements : 8 5 17 80 2 
Ascending order : 2 5 8 17 80 
Decending order : 80 17 8 5 2

Example 4

Test it Now


Exception in thread "main" java.lang.NullPointerException
	at java.util.concurrent.ConcurrentLinkedQueue.toArray(
	at com.javaTpoint.ConcurrentLinkedQueueToArrayExample4.main(

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA