java容器類總結

來源:互聯網
上載者:User

標籤:

java容器類只有兩個主要類型:Collection和Map。

Collection容器每個槽只有一個元素。

Map中持有索引值對關聯。

Collection子介面有List和Set。

    List:以特定次序儲存元素。之類有ArrayList和LinkedList

        ArrayList:擅長隨機訪問。

        LinkedList:擅長插入、刪除和移動元素。

        Vector:同步,安全,效能較低。其餘基本和ArrayList一樣。

    Set:不含重複元素。

        HashSet:使用散列函數。

        TreeSet:使用紅/黑樹狀結構。資料有序排列

        LinkedHashSet:使用鏈表結合散列函數。

Map子類有HashMap、HashTable和TreeMap

    HashMap:允許一個null鍵和多個null值。

    HashTable:不允許null鍵和null值。安全執行緒


容器類輸出方式:Iterator、ListIterator、Enumeration和foreach 

Iterator:

List<String> all = new ArrayList<String>();all.add("hello"); Iterator<String> iter = all.iterator(); while(iter.hasNext()){    System.out.print(iter.next());  }

foreach :

List<String> all = new ArrayList<String>();  all.add("hello");   for(String str:all)   System.out.print(str);

java容器類總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.