一张图

Java容器总结_iterator

三个知识点

1.迭代器


  1. java.util.Iterator+hashNext() next() remove()
  2. java.lang.Iterable+重写iterator()返回一个迭代器(容器需要使用增强for​​foreach​​)

2.比较器


  1. 实体类可以排序 java.lang.Comparable+compareTo
  2. 排序比较器(解耦、应对多种排序规则)java.util.Comparator+重写compare()方法
    容器排序:List+Collections.sort()方法
    TreeSet、TreeMap

3.泛型 <>

泛型类、泛型方法、泛型接口、泛型擦除、通配符?extends super、泛型嵌套

六个接口

Collection、Set、List、Map、Iterator、Comparable

九个常用类(添加,删除,查看+遍历)

1.ArrayList:

底层是数组 适用于查看多余修改 @**@

add(E e) 、
add(int index, E element) 、
remove(int index) 、
remove(Object o) 、
set(int index, E element)、
get(int index)
遍历:1、for+get 2、foreach 3、Iterator 4、ListIterator

2.LinkedList:

底层是链表, 适用于修改多余查看,多了链头与链尾的方法

3.HashSet:

元素不能重复,因此要求元素需要重写hashCode和equals方法

add(E e)
remove(Object o)
遍历:1、foreach 2、Iterator

4.TreeSet:

元素可以排序或者提供排序的业务类

5.HashMap:

键不能重复 必须重写hashCode+equals方法 @**@

put(K key, V value)、
remove(Object key)、
containsKey(Object key)、
containsValue(Object value)
遍历:
获取值:values()、keySet()+get()、entrySet()+getValue()
获取键:keySet()、entrySet()+getKey()
获取键与值:keySet()+get()、entrySet()+getKey()+getValue()

6.Properties:

资源配置文件 相对路径获取文件 @**@

7.Hashtable:

键与值都不能为null 线程安全,效率相对较低

8.Stack:栈

9.Collections:工具类