集合,List三个子类的特点,迭代器Iterator
1、集合
数组和集合的区别:存储长度:数组长度固定;集合长度可变。
存储内容:数组只能存储同一类型元素;集合可以存储多种类型元素。
Collection:List:ArrayList、Vector、LinkedList
Set:HashSet、TreeSet
add();
addAll();
remove();
removeAll();
clear();
contains();
containsAll();
isEmpty();
retainAll();
size();
toArray();
set();
iterator();
ListIterator();
addElement();
elementAt();
elements();
addFirst();
getFirst();
removeFirst();
addLast();
getLast();
removeLast();
2、List三个子类的特点
ArrayList:底层数据结构是数组,查询快,增删慢,线程不安全,效率高。
Vector:底层数据结构是数组,查询快,增删慢,线程安全,效率低。
LinkedList:底层数据结构是链表,查询慢,增删快,线程不安全,效率高。
3、迭代器
迭代器:Iterator接口、ListIterator接口
hasNext();
next();
remove();
hasPrevious();
previous();
set();