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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # 集合 ## 集合繼承關系圖 ![](https://box.kancloud.cn/ff3304c09ec8e6bee72ebf9e835f9bd7_732x350.png) ![](https://img.kancloud.cn/ad/4d/ad4d657ea66480eaeaffa5f4acd7ec79_1033x507.png) list叫鏈,set叫集 list允許存儲重復的,set不允許存儲重復的 ## 基本方法 ~~~ public boolean isEmpty(): 判斷當前集合是否為空 ~~~ ![](https://box.kancloud.cn/6dd774e3a008658cbb6ecc52d70672eb_870x351.png) 創建集合的方式 ~~~ 方式一: Collection<元素類型> 變量名=new ArrayList<元素類型>(); 方式二: Collection 變量名=new ArrayList(): ~~~ ## ArrayList和LinkedList的區別 1. ArrayList是實現了基于動態數組的數據結構,而LinkedList是基于鏈表的數據結構; 2. 對于隨機訪問get和set,ArrayList要優于LinkedList,因為LinkedList要移動指針; 3. 對于添加和刪除操作add和remove,一般大家都會說LinkedList要比ArrayList快,因為ArrayList要移動數據。但是實際情況并非這樣,對于添加或刪除,LinkedList和ArrayList并不能明確說明誰快誰慢 ## 長度的3種表現形式 數組.length 屬性 返回int 字符串.length() 方法,返回值int 集合.size() 方法,返回值int # 迭代器 **集合中把這種取元素的方式描述在Iterator接口中** ## 常用方法 ![](https://box.kancloud.cn/4b769bbef477859254423f91e2706e47_895x198.png) ~~~ //for循環迭代寫法: for (Iterator<String> it2 = coll.iterator(); it2.hasNext(); ) { System.out.println(it2.next()); } //存儲時提升了Object。取出時要使用元素的特有內容,必須向下轉型。 Collection coll = new ArrayList(); coll.add("abc"); coll.add("aabbcc"); coll.add("shitcast"); Iterator it = coll.iterator(); while (it.hasNext()) { //由于元素被存放進集合后全部被提升為Object類型 //當需要使用子類對象特有方法時,需要向下轉型 String str = (String) it.next(); System.out.println(str.length()); } ~~~ # 增強for循環 JDK1.5新特性,增強for循環 JDK1.5版本后,出現新的接口java.lang.Iterable Collection是繼承Iterable Iterable作用,實現增強for循環 **弊端:沒有索引,不能操作容器里面的元素** ## 格式 ~~~ for (數據類型 變量名 : 數組或集合) { } ~~~ ~~~ int[] arr={1,2,3,4,5}; for(int i : arr) { System.out.println(i); } ~~~ # Collections線程安全 java提供的容器類Collection、List、Map、Set、SortedMap、SortedSet都是非線程安全的,當多線程訪問這些容器類時,可能會出現數據同步導致的問題,java的工具類java.util.Collections提供了將非同步對象轉換為同步對象的方法,如下: ~~~ ?? ???? Collections.synchronizedCollection( c); ?? ??? ?Collections.synchronizedList(list) ?? ??? ?Collections.synchronizedMap(m) ?? ??? ?Collections.synchronizedSet(s) ?? ??? ?Collections.synchronizedSortedMap(m) ?? ??? ?Collections.synchronizedSortedSet(s) ~~~ 這些方法的作用就是在原有容器的類的方法內部實現邏輯中加入了同步關鍵字syschronized.
                  <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>

                              哎呀哎呀视频在线观看