<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之旅 廣告
                ### 概述 collection接口是層次結構中的根接口 ,collection表示一組對象,這些對象也稱為collection的元素 .一些collection允許有重復的元素,而另一些則不允許 , 一些collection是有序的,而另一些則是無序的 . list都是有序的,而set則是無序的 . ### 方法 #### clear() ~~~ Collection<String> coll = new ArrayList<String>(); //使用多態的方式,能用多態盡量用多態 coll.add("abc"); coll.add("cba"); coll.clear(); //將元素清空 System.out.println(coll.toString()); ~~~ 結果 ~~~ [] //元素雖然清空,但是集合還是存在的 ~~~ #### contains() 判斷元素是否在集合內 , 返回布爾值 . ~~~ Collection<String> coll = new ArrayList<String>(); coll.add("abc"); coll.add("cba"); System.out.println(coll.contains("abc")); //類型必須一致 ~~~ 結果 ~~~ true ~~~ #### toArray() 將集合中的元素轉成一個數組中的元素,簡單點說就是集合轉數組 . ~~~ Collection<String> coll = new ArrayList<String>(); coll.add("abc"); coll.add("cba"); Object[] obj = coll.toArray(); //這里必須使用object的數組來接收,因為集合可以存儲任意類型的數據 for (int i=0;i<obj.length;i++){ System.out.println(obj[i]); } ~~~ 結果 ~~~ abc cba ~~~ 需要注意的是,轉換成數組之后數組的長度是不能改變的 . #### remove() 移除集合中指定的元素. 返回布爾值,移除成功true,移除失敗為false . ~~~ Collection<String> coll = new ArrayList<String>(); coll.add("abc"); coll.add("cba"); System.out.println(coll.remove("abc")); System.out.println(coll.toString()); ~~~ 結果 ~~~ true [cba] ~~~ 如果集合中有重復的元素,那么移除第一個 .
                  <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>

                              哎呀哎呀视频在线观看