import java.util.*;

/**
 * Created by 一只爱吃萝卜的小兔子 on 2021/11/24 10:41
 * 升序降序  String char 自定义
 */
public class Main {
    public static void main(String[] args) {
        //add()和remove()方法在失败的时候会抛出异常(不推荐)
        Queue<String> queue = new LinkedList<String>();
        //添加元素, offer() 返回的 false。
        queue.offer("a");
        queue.offer("b");
        queue.offer("c");
        queue.offer("d");
        queue.offer("e");
        for (String q : queue) {
            System.out.println(q);
        }
        System.out.println("===");
        System.out.println("poll=" + queue.poll()); //返回第一个元素,并在队列中删除,空null
        for (String q : queue) {
            System.out.println(q);
        }
        System.out.println("-------------------------");
        System.out.println("peek=" + queue.peek()); //返回第一个元素,不删,空null
        for (String q : queue) {
            System.out.println(q);
        }

        System.out.println("-------------------------");
        Iterator it = queue.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("-------------------------");
        while (!queue.isEmpty()) {
            System.out.println(queue.poll());
        }
    }
}