We would like to know how to create a Queue from LinkedList.
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; // www . j a v a 2 s. c o m public class Main { public static void main(String[] args) { Queue<String> myQueue = new LinkedList<String>(); myQueue.add("A"); myQueue.add("B"); myQueue.add("C"); myQueue.add("D"); List<String> myList = new ArrayList<String>(myQueue); for (Object theFruit : myList) System.out.println(theFruit); } }
The code above generates the following result.