---| Collection 集合接口 總接口
------| List 有序 可重復(fù)
---------| ArrayList 底層維護(hù)一個(gè)Object類型的數(shù)組,如果使用無參構(gòu)造方法牢贸,創(chuàng)建ArrayList對(duì)象乱顾,Object數(shù)組
默認(rèn)元素個(gè)數(shù)為10
特征:
查詢快审胸,增刪慢
ensureCapacity(int minCapacity);
trimToSize();
---------| LinkedList 底層維護(hù)的是一個(gè)鏈表
特征:
查詢慢梭纹,增刪快
---------| Vector 線程安全的ArrayList捺僻,不經(jīng)常用
------| Set 無序 不可重復(fù)
---------| HashSet
底層維護(hù)的是一個(gè)哈希表
HashSet存儲(chǔ)原理
hashCode equals
---------| TreeSet
樹形結(jié)構(gòu) 放入的數(shù)據(jù)要不有自然順序恋技,要不存在比較規(guī)則~~
自定義的類對(duì)象放入TreeSet集合
1. 遵從Comparable<T> 接口 實(shí)現(xiàn)compareTo(T o)
2. 實(shí)現(xiàn)自定義比較器 遵從 Comparator<T> 接口 實(shí)現(xiàn)compare(T o1, T o2)
使用了匿名內(nèi)部類
Collection:
add(E e) addAll(Collection<? extends E> c) remove(Object o) clear()
removeAll(Collection c) size() toArray() isEmpty() contains(Object o)
containsAll(Collection c) retainAll(Collection c) removeAll(Collection c)
iterator() equals() hashCode()
迭代器方法:
hasNext() next() remove()
List:
add(int index, E e) addAll(int index, List<? extends > list)
indexOf(Object o) lashIndexOf(Object o) get(int index)
set(int index , E e)
subList(int fromIndex, int toIndex)
ListIterator()
ListIterator()特有方法:
add(E e) set(E e)
Set:
沒有特有方法