LinkedTransferQueue in Java


The LinkedTransferQueue Class in Java has a transfer queue that has unbounded functionality and is based on linked nodes. It uses FIFO for ordering elements. This class implements the Collection interface as well as the AbstractQueue class. It is a part of the Java Collection Framework.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.util.concurrent.LinkedTransferQueue;
public class Demo {
   public static void main(String[] args) throws InterruptedException {
      LinkedTransferQueue<String> ltQueue = new LinkedTransferQueue<String>();
      ltQueue.add("Amy");
      ltQueue.add("John");
      ltQueue.add("May");
      ltQueue.add("Harry");
      ltQueue.add("Anne");
      System.out.println("The elements in LinkedTransferQueue are: " + ltQueue);
   }
}

The output of the above program is as follows −

Output

The elements in LinkedTransferQueue are: [Amy, John, May, Harry, Anne]

Now let us understand the above program.

The LinkedTransferQueue is created and then elements are added to it. Finally it is displayed. A code snippet that demonstrates this is given as follows −

LinkedTransferQueue<String> ltQueue = new LinkedTransferQueue<String>();
ltQueue.add("Amy");
ltQueue.add("John");
ltQueue.add("May");
ltQueue.add("Harry");
ltQueue.add("Anne");
System.out.println("The elements in LinkedTransferQueue are: " + ltQueue);

Updated on: 30-Jul-2019

25 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements