public class QuenDemo {
public static void main(String[] args){
//public class Queue extends Collection
Queue<Integer> queue=new LinkedList<Integer>();
Random rand = new Random(47);
for(int i=0;i<10;i++){
queue.offer(rand.nextInt(i+10));
}
System.out.println("1111"+queue.toString());
printQ(queue);
//public class LinkedList extends AbstractSequentialList implements List,Queue,Cloneable,Serializable
Queue<Character> qc=new LinkedList<Character>();
for(char c:"guoxzh".toCharArray()){
qc.offer(c);
System.out.println("qc=="+qc.toString());
}
printQ(qc);
}
public static void printQ(Queue queue){
while(queue.peek()!=null){
//peek和element都是在不移除的情况下返回对头,但是peek在队列为空的情况下返回null,element方法会抛出NoSuchElementException异常
System.out.println(queue.remove());
//remove和poll方法都是在移除并返回对头,但是poll在为空时返回null,而remove会抛出NoSucheElementException异常
System.out.println("2222"+queue.toString());
}
}
}