
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
ConcurrentLinkedQueue in Java
The ConcurrentLinkedQueue class in Java is used to implement a queue using a concurrent linked list. This class implements the Collection interface as well as the AbstractCollection class. It is a part of the Java Collection Framework.
A program that demonstrates this is given as follows −
Example
import java.util.concurrent.*; public class Demo { public static void main(String[] args) { ConcurrentLinkedQueue<String> clQueue = new ConcurrentLinkedQueue<String>(); clQueue.add("Amy"); clQueue.add("John"); clQueue.add("May"); clQueue.add("Harry"); clQueue.add("Anne"); System.out.println("The elements in ConcurrentLinkedQueue are: " + clQueue); } }
The output of the above program is as follows −
Output
The elements in ConcurrentLinkedQueue are: [Amy, John, May, Harry, Anne]
Now let us understand the above program.
The ConcurrentLinkedQueue is created and then elements are added to it. Finally, it is displayed. A code snippet that demonstrates this is given as follows −
ConcurrentLinkedQueue<String> clQueue = new ConcurrentLinkedQueue<String>(); clQueue.add("Amy"); clQueue.add("John"); clQueue.add("May"); clQueue.add("Harry"); clQueue.add("Anne"); System.out.println("The elements in ConcurrentLinkedQueue are: " + clQueue);
Advertisements