1.Collection、Map类关系。
Collection:父接口
List接口: ArrayList、LinkedList
Set接口:HashSet、TreeSet
Map接口: HashMap实现类、 HashTable实现类、TreeMap实现类。
2.Collection接口常用方法
size():大小
isEmpty():是否为空
add(Object):添加元素
remove(Object):移除元素
clear():清空所有元素
toArray():转Object数组
contains(‘l’):是否包含某个元素
3.List接口常用方法
add("");
add(0,"");
remove(2);
set(2,‘2’);
get(2);
indexOf();
lastIndexOf();
4.ArrayList常用方法
addAll(list);
removeAll(list);
retainAll(list);
containsAll(list);
5.ArrayList和LinkedList比较
ArrayList:线程不安全,查询效率高,删除效率低。length+(length>>1)
LinkedList:线程安全,查询效率低,删除效率高。
6.Map(HashMap、TreeMap、HashTable)
HashMap:底层是基于数组+链表实现的。0.75*length就会扩大2倍。
TreeMap是基于红黑树实现,根据key值自动排序。实现Comparable接口,自定义排序方式。
HashTable:线程不安全,效率低。不允许key和value值为空。
7.Set接口
List接口:有序,可重复。Set接口:无序,不可重复。
HashSet:实现原理是HashMap
TreeSet:实现原理是TreeMap,可以实现排序。
8.Collections是Set、List、Map,工具类
常用方法:shuffle(list):随机排列
reverse(list):逆序
sotr();排序。
binarySearch(list,“ll”);二分法查找元素内容。