Java comes with its own builtin Queue interface.
Lets see a simple program using Queue Interface
import java.util.*;
public class BuiltInQueue {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Queue<Integer> q=new LinkedList<Integer>();
int c,n;
Scanner S=new Scanner(System.in);
while(true){
System.out.println(“1)enqueue,2)dequeue,3)peek,4)exit”);
c=S.nextInt();
switch(c){
case 1: System.out.println(“enter number”);
n=S.nextInt();
q.add(n);
break;
case 2:System.out.println(q.poll());
break;
case 3:System.out.println(q.peek());
break;
case 4:System.exit(0);
}
}
}
}