Collection小结

1.Collection是集合类的一个总的接口。Collection有两个子接口:List和Set。Map是一个接口,但是不继承Collection。

2.List接口的子类:ArrayList、LinkedList、Vector

3.Set接口的子类:TreeSet、HashSet、LinkedHashSet。

4.Map接口的子类:TreeMap、HashMap、LinkedHashMap。

5.底层实现

  • ArrayList:数组
  • LinkedList:链表
  • Vector:数组
  • TreeSet:TreeMap                       TreeMap:红黑树
  • HashSet:HashMap                     HashMap:数组+链表(jdk1.7) 数组+链表+红黑树(jdk:1.8以后)
  • LinkedHashSet:红黑树+链表

6.如果往TreeSet等树形存储结构中添加元素(引用对象),需要定义比较器。比较器分为外部比较器(Comparable)和内部比较器(Comparator)

7.在集合中添加元素,可以使用泛型对添加元素的类型进行约定。泛型有泛型类,泛型接口和泛型方法。有3种通配符:(泛型上限)、(泛型下限)

8.HashMap中查找元素的速度比TreeMap快。

9.TreeMap存储的是Key-value值,TreeSet也是实际上是TreeMap结构,只存储key值。

 

 

你可能感兴趣的:(java学习)