List是元素有序并且可以重复的集合。
List的主要实现:ArrayList、LinkedList、Vector。
List常用方法
- 增:add(index,element) addAll(index,Collection)
- 删:remove(index) removeAll(Collection) clear()
- 改:set(index,element)
- 获取:get(index) subList(from,to) listIterator() indexOf(obj) size()
- 判断:isEmpty() contains(Collection)
ArrayList、LinkedList、Vector的区别
ArrayList的底层实现是数组,不同步,非线程安全,效率高,支持随机访问,而且查询快,增删慢,默认容量为10,扩容机制:
int newCapacity=oldCapacity+(oldCapacity>>1); //1.5倍
LinkedList的底层实现是双向链表,不同步,非线程安全,效率高,查询慢,增删快。
Vector的底层实现为数组,同步,线程安全,效率低,查询快,增删慢,默认容量为10。