- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a Queue from LinkedList in Java?
Let us create a queue from LinkedList like this −
Queue<String>queue = new LinkedList<String>(); queue.add("P"); queue.add("Q"); queue.add("R"); queue.add("S"); queue.add("T"); queue.add("U"); queue.add("V");
Now, use a List to display the elements of the queue −
List<String>list = new ArrayList<String>(queue);
Example
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; public class Demo { public static void main(String[] args) { Queue<String>queue = new LinkedList<String>(); queue.add("P"); queue.add("Q"); queue.add("R"); queue.add("S"); queue.add("T"); queue.add("U"); queue.add("V"); List<String>list = new ArrayList<String>(queue); for (Object ob: list) System.out.println(ob); } }
Output
P Q R S T U V
- Related Articles
- Create a queue using LinkedList class in Java
- Create an object array from elements of LinkedList in Java
- How to create Java Priority Queue to ignore duplicates?
- Implement a stack from a LinkedList in Java
- Java Program to Access elements from a LinkedList
- Create a Queue from another collection in C#?
- Get SubList from LinkedList in Java
- How to remove an element from ArrayList or, LinkedList in Java?
- Remove a specific element from a LinkedList in Java
- Create a Stack and Queue using ArrayDeque in Java
- C# Program to create a LinkedList
- Retrieve the last element from a LinkedList in Java
- How many ways to iterate a LinkedList in Java?
- Remove an element from a Queue in Java
- Remove a range of elements from a LinkedList in Java

Advertisements