Collection
Collection collection=new ArrayList();//接口不能创建对象,利用实体类创建对象
增加:add(E e) ,addAll(Collection<? extends E> e )
//集合只能放引用数据类型,不能放基本数据类型,所以添加数据的时候涉及自动装箱
//int——>Integer
删除:clear()//清空集合 remove(Object object)//删除集合中指定元素
查看:iterator迭代器
遍历集合:Iterator iterator=collection.iterator();
while(iterator.hasNext()){//判断是否有下一个元素,有则为true
System.out.println(iterator.next());//next方法获取元素,并将指针下移
}
size()//判断集合中元素数量
isEmpt()//判断是否为空
contains(Object object)//是否包含元素
equals(Object object)//比较值 若为==比较地址值
List接口
add() //增加元素 add(int index,E element)//在指定下标增加元素
remove(int index) renmove(Object o) //删除元素
set(int index,E element)//修改元素
get(int index)//查看元素
List集合遍历
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}
//增强for
for(Object o:list){
System.out.println(o);
}
//迭代器
Iterator i=list.iterator();
while(i.hasNext()){
System.out.println(i.next());
}