Java集合 - Collection

Ref:http://blog.csdn.net/liulin_good/article/details/6213815

    http://www.cnblogs.com/averey/p/4306166.html

一、java.util.Iterator<E>接口

  迭代器

 1 package java.util;
 2 
 3 public interface Iterator<E>{
 4     // Return true iteration has more elements
 5     boolean hasNext();
 6 
 7     // Return the next element in the iteration
 8     E next();
 9 
10     // Remove the last element returned by this iterator. This method can be called only once per call to next
11     void remove();
12 }
View Code

 

二、java.util.Collection接口

   继承java.lang.Iterable接口,包含iterator()方法返回Iterator<T>

 1 package java.util;
 2 
 3 public interface Collection<E> extends Iterable<E>{
 4     
 5     int size();
 6     
 7     boolean isEmpty();
 8     
 9     boolean contains(Object o);
10     
11     Iterator<E> iterator();
12     
13     Object[] toArray();
14     
15     // <T>:申明T为泛型。参考:http://www.zhihu.com/question/31967519
16     <T> T[] toArray(T[] a);
17     
18     boolean add(E e);
19     
20     boolean remove(Object o);
21     
22     //Collection<?>:未知Collection,该Collection的元素类型可以匹配任意类型
23     boolean containsAll(Collection<?> c);
24     
25     boolean addAll(Collection<? extends E> c);
26     
27     boolean removeAll(Collection<?> c);
28     
29     //保留该集合中在目标集合中的元素
30     boolean retainAll(Collection<?> c);
31     
32     void clear();
33     
34     boolean equals(Object o);
35     
36     int hashCode()
37 }
View Code

 

三、Collection类型层次

 

posted @ 2016-03-16 21:54  iszer  阅读(133)  评论(0)    收藏  举报