-
集合方法Collection
1、添加
boolean add(E e) 添加1个
boolean addAll(collection<? extends E> c) 添加指定容器中的所有元素
2、删除
void clear() 清空所有
boolean remove() 删除一个
boolean removeAll(collection<? extends E> c) 删除指定容器中的所有元素
boolean retainAll(collection<? extends E> c) 移除指定容器中不同的元素
3、获取长度
int size()
4、判断
boolean isEmpty() 是否为空
boolean contains(Object o) 包含某个元素
boolean containsAll(Collection<? extends E> c)包含某个指定容器中的元素
5、将集合转成数组
Object[] toArray()
6、取出集合元素
Iterator iterator()
获取集合中元素上迭代功能的迭代器对象
迭代:取出元素的一种方式
迭代器:具备迭代功能的对象。NoSuchElementException
迭代器是取出Collection集合元素的公共方式 -
List 接口中的特有方法:围绕索引来定义的
有序(存入的顺序和取出的顺序一致),有索引(核心功能),允许重复元素
支持增删该查
增:
add(index,element)插入
删
remove(index)
改
set(index,newElement)
查
int indexOf(element)
element get(index)
List集合特有的取出方式 for循环get 迭代器
ConcurrentModificationException
迭代过程中使用了集合对象同时对元素进行操作。导致了迭代的不确定性。引发了该异常。
List集合特有的迭代器,listIterator
不允许重复元素
网友评论