<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 選擇合適的 Java 集合 > 原文: [https://javatutorial.net/choose-the-right-java-collection](https://javatutorial.net/choose-the-right-java-collection) Java 為您提供了多種收集實現供您選擇。 通常,您將始終為您的編程任務尋找性能最佳的集合,在大多數情況下為[`ArrayList`](https://javatutorial.net/java-arraylist-example),[`HashSet`](https://javatutorial.net/java-concurrenthashset-example)或[`HashMap`](https://javatutorial.net/java-identityhashmap-example)。但是請注意,如果您需要某些特殊功能(例如排序或排序),則可能需要進行特殊的實現。 該 Java 集合教程不包括[`WeakHashMap`](https://javatutorial.net/java-weakhashmap-example)等很少使用的類,因為它們是為非常特定或特殊任務設計的,因此在 99% 的情況下都不應該選擇它們。 如果您需要深入了解特定集合的實現方式,則可能需要閱讀官方的[集合框架教程](http://docs.oracle.com/javase/7/docs/technotes/guides/collections/index.html "Collections Framework Tutorial")。 首先讓我們看下面的流程圖。 它將幫助您根據要存儲到此集合中的數據確定要使用的集合接口。 ![java collection interfaces flowchart](https://img.kancloud.cn/aa/34/aa343cf8bf277d880ea4d3f222d908c7_528x282.jpg) 這里的主要規則是:如果您需要存儲映射了鍵的值,請轉到`Map`接口,否則,請使用`List`表示可能重復的值,如果您不想在集合中使用重復的值,請最終使用`Set`接口。 ## 選擇正確的 Java `Map`接口 [`HashMap`](https://javatutorial.net/java-identityhashmap-example) –如果迭代時項目的順序對您不重要,請使用此實現。與`TreeMap`和[`LinkedHashMap`](https://javatutorial.net/java-linkedhashmap-example)相比,`HashMap`具有更好的性能。 [`TreeMap`](https://javatutorial.net/java-treemap-example) – 已排序和排序,但比`HashMap`慢。[`TreeMap`](https://javatutorial.net/java-treemap-example)根據其比較器具有鍵的升序 [`LinkedHashMap`](https://javatutorial.net/java-linkedhashmap-example) – 在插入過程中按鍵對項目排序 ## 選擇正確的 Java `List`接口 [`ArrayList`](https://javatutorial.net/java-arraylist-example) –插入期間對項目進行排序。與對`LinkedLists`的搜索操作相比,對`ArrayLists`的搜索操作更快 [`LinkedList`](https://javatutorial.net/java-linkedlist-example) – 已快速添加到列表的開頭,并通過迭代從內部快速刪除 ## 選擇正確的 Java `Set`接口 [`HashSet`](https://javatutorial.net/java-concurrenthashset-example) – 如果迭代時項目的順序對您不重要,請使用此實現。與`TreeSet`和`LinkedHashSet`相比,`HashSet`具有更好的性能 `LinkedHashSet` – 在插入過程中排序元素 [`TreeSet`](https://javatutorial.net/java-treeset-example) – 根據其比較器,按鍵的升序排序
                  <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>

                              哎呀哎呀视频在线观看