<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### [簡單集合分類](https://lingcoder.gitee.io/onjava8/#/book/12-Collections?id=%e7%ae%80%e5%8d%95%e9%9b%86%e5%90%88%e5%88%86%e7%b1%bb) 可以看到,實際上只有四個基本的集合組件:**Map**,**List**,**Set**和**Queue**,它們各有兩到三個實現版本(**Queue**的**java.util.concurrent**實現未包含在此圖中)。最常使用的集合用黑色粗線線框表示。 虛線框表示接口,實線框表示普通的(具體的)類。帶有空心箭頭的虛線表示特定的類實現了一個接口。實心箭頭表示某個類可以生成箭頭指向的類的對象。例如,任何**Collection**都可以生成**Iterator**,**List**可以生成**ListIterator**(也能生成普通的**Iterator**,因為**List**繼承自**Collection**)。 下面的示例展示了各種不同的類在方法上的差異。實際代碼來自[泛型](https://lingcoder.gitee.io/onjava8/#/)章節,在這里只是調用它來產生輸出。程序的輸出還展示了在每個類或接口中所實現的接口: ~~~ // collections/CollectionDifferences.java import onjava.*; public class CollectionDifferences { public static void main(String[] args) { CollectionMethodDifferences.main(args); } } /* Output: Collection: [add, addAll, clear, contains, containsAll, equals, forEach, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray] Interfaces in Collection: [Iterable] Set extends Collection, adds: [] Interfaces in Set: [Collection] HashSet extends Set, adds: [] Interfaces in HashSet: [Set, Cloneable, Serializable] LinkedHashSet extends HashSet, adds: [] Interfaces in LinkedHashSet: [Set, Cloneable, Serializable] TreeSet extends Set, adds: [headSet, descendingIterator, descendingSet, pollLast, subSet, floor, tailSet, ceiling, last, lower, comparator, pollFirst, first, higher] Interfaces in TreeSet: [NavigableSet, Cloneable, Serializable] List extends Collection, adds: [replaceAll, get, indexOf, subList, set, sort, lastIndexOf, listIterator] Interfaces in List: [Collection] ArrayList extends List, adds: [trimToSize, ensureCapacity] Interfaces in ArrayList: [List, RandomAccess, Cloneable, Serializable] LinkedList extends List, adds: [offerFirst, poll, getLast, offer, getFirst, removeFirst, element, removeLastOccurrence, peekFirst, peekLast, push, pollFirst, removeFirstOccurrence, descendingIterator, pollLast, removeLast, pop, addLast, peek, offerLast, addFirst] Interfaces in LinkedList: [List, Deque, Cloneable, Serializable] Queue extends Collection, adds: [poll, peek, offer, element] Interfaces in Queue: [Collection] PriorityQueue extends Queue, adds: [comparator] Interfaces in PriorityQueue: [Serializable] Map: [clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, replace, replaceAll, size, values] HashMap extends Map, adds: [] Interfaces in HashMap: [Map, Cloneable, Serializable] LinkedHashMap extends HashMap, adds: [] Interfaces in LinkedHashMap: [Map] SortedMap extends Map, adds: [lastKey, subMap, comparator, firstKey, headMap, tailMap] Interfaces in SortedMap: [Map] TreeMap extends Map, adds: [descendingKeySet, navigableKeySet, higherEntry, higherKey, floorKey, subMap, ceilingKey, pollLastEntry, firstKey, lowerKey, headMap, tailMap, lowerEntry, ceilingEntry, descendingMap, pollFirstEntry, lastKey, firstEntry, floorEntry, comparator, lastEntry] Interfaces in TreeMap: [NavigableMap, Cloneable, Serializable] */ ~~~ 除**TreeSet**之外的所有**Set**都具有與**Collection**完全相同的接口。**List**和**Collection**存在著明顯的不同,盡管**List**所要求的方法都在**Collection**中。另一方面,在**Queue**接口中的方法是獨立的,在創建具有**Queue**功能的實現時,不需要使用**Collection**方法。最后,**Map**和**Collection**之間唯一的交集是**Map**可以使用`entrySet()`和`values()`方法來產生**Collection**。 請注意,標記接口**java.util.RandomAccess**附加到了**ArrayList**上,但不附加到**LinkedList**上。這為根據特定**List**動態改變其行為的算法提供了信息。 從面向對象的繼承層次結構來看,這種組織結構確實有些奇怪。但是,當了解了**java.util**中更多的有關集合的內容后(特別是在[附錄:集合主題](https://lingcoder.gitee.io/onjava8/#/)中的內容),就會發現除了繼承結構有點奇怪外,還有更多的問題。集合類庫一直以來都是設計難題——解決這些問題涉及到要去滿足經常彼此之間互為牽制的各方面需求。所以要做好準備,在各處做出妥協。 盡管存在這些問題,但 Java 集合仍是在日常工作中使用的基本工具,它可以使程序更簡潔、更強大、更有效。你可能需要一段時間才能熟悉集合類庫的某些方面,但我想你很快就會找到自己的路子,來獲得和使用這個類庫中的類。 \[^1\]: 許多語言,例如 Perl ,Python 和 Ruby ,都有集合的本地支持。 \[^4\]:`remove()`是一個所謂的“可選”方法(還有一些其它的這種方法),這意味著并非所有的**Iterator**實現都必須實現該方法。這個問題將在[附錄:集合主題](https://lingcoder.gitee.io/onjava8/#/)中介紹。但是,標準 Java 庫集合實現了`remove()`,因此在[附錄:集合主題](https://lingcoder.gitee.io/onjava8/#/)章節之前,都不必擔心這個問題。 \[^5\]: 這實際上依賴于具體實現。優先級隊列算法通常會按插入順序排序(維護一個*堆*),但它們也可以在刪除時選擇最重要的元素。 如果對象的優先級在它在隊列中等待時可以修改,那么算法的選擇就顯得很重要了。 \[^6\]: 有些人提倡這樣一種自動創建機制,即對一個類中所有可能的方法組合都自動創建一個接口,有時候對于單個的類都是如此。 我相信接口的意義不應該僅限于方法組合的機械地復制,因此我在創建接口之前,總是要先看到增加接口帶來的價值。 \[^7\]: 這在 Java 5 之前是不可用的,因為該方法被認為與操作系統的耦合度過緊,因此違反“一次編寫,處處運行”的原則。現在卻提供它,這一事實表明, Java 的設計者們更加務實了。 \[^8\]: 下面是譯者繪制的 Java 集合框架簡圖,黃色為接口,綠色為抽象類,藍色為具體類。虛線箭頭表示實現關系,實線箭頭表示繼承關系。![collection](https://lingcoder.gitee.io/onjava8/images/collection.png)![map](https://lingcoder.gitee.io/onjava8/images/map.png)
                  <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>

                              哎呀哎呀视频在线观看