Collection集合基础知识
package com.day15.collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
public class CollectionIterator {
public static void main(String[] args) {
Collection c=new ArrayList();
c.add("a");
c.add("b");
c.add("c");
c.add("d");
Iterator it =c.iterator();//获取迭代器
/* boolean b1=it.hasNext();//判断集合中是否有元素,有就返回true
Object obj1=it.next();
System.out.println(b1);//true
System.out.println(obj1);//a
boolean b2=it.hasNext();//判断集合中是否有元素,有就返回true
Object obj2=it.next();
System.out.println(b2);//true
System.out.println(obj2);//b
*/ /*while(it.hasNext()) {
System.out.println(it.next());
}*/
Collection c1=new HashSet();
c1.add("a");
c1.add("f");
c.removeAll(c1);
System.out.println(c.toString());//[b, c, d] 删除两个对象的交集,因为collection接口的实现类AbstractList重写了toString()方法,ArrayList类继承了AbstractList类
}
}