java集合架構+應用小技巧

來源:互聯網
上載者:User

標籤:如何   width   linked   nta   next   system   tor   dog   lis   

一、大體介紹

1.介面

集體介面在collections:

提供了對集合進行排序,遍曆等多種演算法的實現

List是不唯一,有序的

Set是唯一,有序的

 

1.ArrayList 不唯一  有序  遍曆效率高

2.LinkedList採用連結的方式,插入和刪除的時候效率高

 

alt + s + r 產生set,get方法

alt +  / 產生構造方法

 

添加

lis.add(dog1);

lis.add(dog2);

這裡添加的是object對象

lis.size()定義數組的長度

lis.remove(0);                          //刪除索引號為0的對象

lis.remove(dog0);     //按照指定的對象名刪除

 

 2.HashSet-1

3.Set

Set介面儲存一組唯一,無序的對象

HashSet是Set介面常用的實作類別

Set中存放對象的引用

 

 

4.Iterator

 如何遍曆Set集合

 

 

方法一

通過迭代器Iterator實現遍曆

1.擷取Iterator:Collection介面的iterator()方法

Iterator的方法

--boolean hasNext():判斷是否存在另一個可 訪問的元素

--Object next():返回要訪問的下一個元素

 

方法二

增強型for迴圈

 

 

5.HashMap

Map countries = new HashMap();

countries.get("key值");

countries.containsKey("key值");返回boolean型

countries.containsValue("對應的值");返回boolean型

刪除

countries.remove("FR");

 

遍曆

System.out.println(countries.keySet());

System.out.println(countries.values());

System.out.println(countries);

 

清空

countries.clear()

 

查看是否為空白

isEmpty()

 

Vector與ArrayList

 

 

 如何遍曆Map中的集合

 

 

 

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.