
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
Create 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
Advertisements