Collection

 


基本功能

boolean add(E e)

boolean remove(Object o)

void clear()

boolean contains(Object o)

boolean isEmpty()

int size()

 


注意

collectionXxx.java使用了未经检查或不安全的操作.

注意:要了解详细信息,请使用 -Xlint:unchecked重新编译.

java编译器认为该程序存在安全隐患

温馨提示:这不是编译失败,所以先不用理会,等学了泛型你就知道了

带All的功能

boolean addAll(Collection c)

boolean removeAll(Collection c)

boolean containsAll(Collection c)

boolean retainAll(Collection c) 注:A集合对B集合取交集,获取的交集元素存储到A集合中,返回的boolean的类型的值代表的意思是A集合是否发生了改变.

 


遍历功能

Iterator<E> iterator()

Iterator:

public boolean hasNext() ;

public E next() ; next方法获取的元素后指针向后移动一位

 


集合转换成数组的功能

Object[] toArray() ;

 


迭代器

* 集合是用来存储元素,存储的元素需要查看,那么就需要迭代(遍历)

* 迭代器的使用

Collection c = new ArrayList();

c.add("a");

c.add("b");

Iterator it = c.iterator(); //获取迭代器的引用

while(it.hasNext()) { u //集合中的迭代方法(遍历)

System.out.println(it.next());

posted on 2017-02-16 19:51  LoaderMan  阅读(168)  评论(0编辑  收藏  举报

导航