import java.util.*;
public class Ex_Queue_2{
public static void main(String args[]){
Queue q1 = new LinkedList();
q1.offer("First");
Queue q2 = new LinkedList();
q2.offer("Second");
System.out.println(q1.poll());
System.out.println(q1.toString()+"\n");
System.out.println(q2.peek());
System.out.println(q2.toString());
}
}
First
[]
Second
[Second]
poll()和peek()差別在於poll會將元素移除, 而peek只會顯示
沒有留言:
張貼留言