<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## [隊列Queue](https://lingcoder.gitee.io/onjava8/#/book/12-Collections?id=%e9%98%9f%e5%88%97queue) 隊列是一個典型的“先進先出”(FIFO)集合。 即從集合的一端放入事物,再從另一端去獲取它們,事物放入集合的順序和被取出的順序是相同的。隊列通常被當做一種可靠的將對象從程序的某個區域傳輸到另一個區域的途徑。隊列在[并發編程](https://lingcoder.gitee.io/onjava8/#/)中尤為重要,因為它們可以安全地將對象從一個任務傳輸到另一個任務。 **LinkedList**實現了**Queue**接口,并且提供了一些方法以支持隊列行為,因此**LinkedList**可以用作**Queue**的一種實現。 通過將**LinkedList**向上轉換為**Queue**,下面的示例使用了在**Queue**接口中與**Queue**相關(Queue-specific)的方法: ~~~ // collections/QueueDemo.java // Upcasting to a Queue from a LinkedList import java.util.*; public class QueueDemo { public static void printQ(Queue queue) { while(queue.peek() != null) System.out.print(queue.remove() + " "); System.out.println(); } public static void main(String[] args) { Queue<Integer> queue = new LinkedList<>(); Random rand = new Random(47); for(int i = 0; i < 10; i++) queue.offer(rand.nextInt(i + 10)); printQ(queue); Queue<Character> qc = new LinkedList<>(); for(char c : "Brontosaurus".toCharArray()) qc.offer(c); printQ(qc); } } /* Output: 8 1 1 1 5 14 3 1 0 1 B r o n t o s a u r u s */ ~~~ `offer()`是與**Queue**相關的方法之一,它在允許的情況下,在隊列的尾部插入一個元素,或者返回**false**。`peek()`和`element()`都返回隊頭元素而不刪除它,但是如果隊列為空,則`element()`拋出**NoSuchElementException**,而`peek()`返回**null**。`poll()`和`remove()`\* 都刪除并返回隊頭元素,但如果隊列為空,`poll()`返回**null**,而`remove()`拋出**NoSuchElementException**。 自動包裝機制會自動將`nextInt()`的**int**結果轉換為**queue**所需的**Integer**對象,并將**char c**轉換為**qc**所需的**Character**對象。**Queue**接口窄化了對**LinkedList**方法的訪問權限,因此只有適當的方法才能使用,因此能夠訪問到的**LinkedList**的方法會變少(這里實際上可以將**Queue**強制轉換回**LinkedList**,但至少我們不鼓勵這樣做)。 與**Queue**相關的方法提供了完整而獨立的功能。 也就是說,對于**Queue**所繼承的**Collection**,在不需要使用它的任何方法的情況下,就可以擁有一個可用的**Queue**。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看