**集合继承体系**
1. 集合接口继承体系
Iterable<E>
↓
Collection<E>
↓ ↓
List<E> Set<E>
2. ArrayList继承体系
AbstractCollection<E> → Collection<E>
↓
AbstractList<E> → List<E>
↓
ArrayList<E> → (List<E>, RandomAccess, Cloneable, java.io.Serializable)
3. HashSet继承体系
AbstractCollection<E> → Collection<E>
↓
AbstractSet<E> → Set<E>
↓
HashSet<E> → (Set<E>, Cloneable, java.io.Serializable)
4. HashMap继承体系
AbstractMap<K,V> → Map<K,V>
↓
HashMap<K,V> → (Map<K,V>, Cloneable, Serializable)
Iterable<E>
接口方法:
1. Iterator<T> iterator(); // 迭代器 iterator.hasNext; iterator.next
2. default void forEach(Consumer<? super T> action); // 遍历元素
Collection<E>
接口方法:
1. int size();
2. boolean isEmpty();
3. boolean contains(Object o);
4. Iterator<T> iterator(); // 覆写父接口中方法 为了增加复读性
5. Object[] toArray();
6. <T> T[] toArray(T[] a);
7. boolean add(E e);
8. boolean remove(Object o);
9. boolean containsAll(Collection<?> c);
10. boolean addAll(Collection<? extends E> c);
11. boolean removeAll(Collection<?> c);
12. default boolean removeIf(Predicate<? super E> filter); //删除满足条件的元素
13. boolean retainAll(Collection<?> c);
14. void clear();
15. boolean equals(Object o);
16. int hashCode();
List<E>
接口方法:
1. boolean addAll(int index, Collection<? extends E> c);
2. default void sort(Comparator<? super E> c); //排序
3. E get(int index);
4. E set(int index, E element);
5. void add(int index, E element);
6. E remove(int index);
7. int indexOf(Object o);
8. int lastIndexOf(Object o);
9. ListIterator<E> listIterator();
10. ListIterator<E> listIterator(int index);
11. List<E> subList(int fromIndex, int toIndex);
Set<E>
接口方法:
1. 无扩展接口
Map<K, V>
接口方法:
1. int size();
2. boolean isEmpty();
3. boolean containsKey(Object key);
4. boolean containsValue(Object value);
5. V get(Object key);
6. V put(K key, V value);
7. V remove(Object key);
8. void putAll(Map<? extends K, ? extends V> m);
9. void clear();
10. Set<K> keySet();
11. Collection<V> values();
12. Set<Map.Entry<K, V>> entrySet();
13. boolean equals(Object o);
14. int hashCode();
15. default V getOrDefault(Object key, V defaultValue)
16. default void forEach(BiConsumer<? super K, ? super V> action)
17. default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
18. default V putIfAbsent(K key, V value)
19. default boolean remove(Object key, Object value)
20. default boolean replace(K key, V oldValue, V newValue)
21. default V replace(K key, V value)
22. default V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)
23. default V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)
AbstractCollection<E> // 集合抽象类
已实现接口方法:(Collection<E>)
1. boolean isEmpty();
2. boolean contains(Object o);
3. Object[] toArray();
4. <T> T[] toArray(T[] a);
5. boolean remove(Object o);
6. boolean containsAll(Collection<?> c)
7. boolean addAll(Collection<? extends E> c);
8. boolean removeAll(Collection<?> c);
9. boolean retainAll(Collection<?> c);
10. void clear();
11. toString();
抽象方法
1. abstract Iterator<E> iterator();
2. abstract int size();
抛异常方法
1. boolean add(E e); // throw Exception
AbstractList<E> // List抽象类
已实现接口方法
1. int indexOf(Object o); → List<E>
2. int lastIndexOf(Object o); → List<E>
3. boolean addAll(int index, Collection<? extends E> c); → List<E>
4. ListIterator<E> listIterator(); → List<E>
5. ListIterator<E> listIterator(final int index); → List<E>
6. List<E> subList(int fromIndex, int toIndex);
实现父类抽象方法
1. Iterator<E> iterator(); → AbstractCollection<E>
重写父类方法
1. void clear(); → AbstractCollection<E>
2. boolean equals(Object o);
3. int hashCode();
抽象方法
1. abstract public E get(int index);
抛异常方法
1. boolean add(E e); // throw Exception
2. void add(int index, E element); // throw Exception
3. E set(int index, E element);
4. E remove(int index);
AbstractSet<E> // Set抽象类
覆写父类方法
1. boolean equals(Object o);
2. int hashCode();
3. removeAll(Collection<?> c);
AbstractMap<K,V> // Map抽象类
实现Map<K, V> 方法
1. int size();
2. boolean isEmpty();
3. boolean containsValue(Object value);
4. boolean containsKey(Object key);
5. V get(Object key);
6. V put(K key, V value);
7. V remove(Object key);
8. void putAll(Map<? extends K, ? extends V> m);
9. void clear();
10. Set<K> keySet();
11. Collection<V> values()
复写父类方法
1. boolean equals(Object o);
2. int hashCode();
3. String toString();
4. Object clone();
抽象方法
1. abstract Set<Entry<K,V>> entrySet();