java Iterator Iterable Collection AbstractCollection Map關係

來源:互聯網
上載者:User

標籤:add   stat   介面   lan   alt   抽象   value   asn   返回   

 

 java.lang

Interface Iterable<T>  實現該介面就可以使用for-each迴圈。

 

java.util

Interface Iterator<E>  用於遍曆Collection,有hasNext(),next(),remove()方法。

 

java.util

Interface Collection<E>  整個Collection體系中的根介面,父類介面是Iterable。可以產生Iterator。

 

java.util

Interface Map<K,V>  Map並不是Collection,它只是可以產生Collection。Iterator是作用於Collection的,並不能直接用於Map。

 

java.util

public static Interface Map.Entry<K,V> 是 Map<K,V>的嵌套類,一個Map.Entrymap就是map裡的一個條目。 Map的entrySet()方法返回Set<Map.Entry<K,V>>,可以用於遍曆map。

1 //推薦,尤其是容量大時2 for (Map.Entry<String, String> entry : map.entrySet()) {3   System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());4 }

 

java.util

Class AbstractCollection<E> 該抽象類別給出類Collection介面最基本的實現,將實現Collection介面的工作最小化。AbstractList, AbstractQueue, AbstractSet, ArrayDeque一個道理。

java.util

Collections和Arrays是工具類,所有方法都是靜態。Collections一個常用的方法

public static <T> boolean addAll(Collection<? super T> c, T... elements) 將elements添加到collection中,elements可以是一個一個的也可以是數組。

 Arrays也有類似的方法 public static <T> List<T> asList(T... a)。

java Iterator Iterable Collection AbstractCollection Map關係

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.