Collection集合,collection

來源:互聯網
上載者:User

Collection集合,collection

 

一些關於集合內部演算法可以查閱這篇文章《容器類總結》。

 

(Abstract+)

Collection

子類:List,Queue,Set

增:

  • add(E):boolean
  • addAll(Collection<? extends E>):boolean

刪:

  • remove(Object):boolean
  • removeAll(Collection<?>):boolean
  • retainAll(Collection<?>):boolean
  • removeIf(Predicate<? super E>):boolean
  • clear()

查:

  • contains(Object):boolean
  • containsAll(Collection<?>):boolean
  • size():int
  • isEmpty():boolean
  • toArray():Object[]
  • toArray(T[]):T[]
  • Collections.max(Collection<? extends T>):T
  • Collections.max(Collection<? extends T>, Comparator<? super T>):T
    求最大值
  • Collections.min(Collection<? extends T>):T
  • Collections.min(Collection<? extends T>, Comparator<? super T>):T
    求最小值

工具:

  • iterator():Iterator<E>
  • spliterator():Spliterator<E>
  • stream():Stream<E>
  • parallelStream():Stream<E>
  • Collections.unmodifiableCollection(Collection<? extends T>):Collection<T>
    唯讀模式封裝
  • Collections.synchronizedCollection(Collection<T>):Collection<T>
    安全執行緒封裝

 

(Abstract+)

(AbstractSequentia+)

List

父類:Collection

子類:ArrayList,LinkedList,Vector,Stack

增:

  • add(int, E)
  • addAll(int, Collection<? extends E>):boolean

刪:

  • remove(int):E

改:

  • set(int, E):E
  • replaceAll(UnaryOperator<E>)
  • sort(Comparator<? super E>)
  • Collections.swap(List<?>, int, int)
    交換兩元素位置

查:

  • get(int):E
  • indexOf(Object):int
  • lastIndexOf(Object):int
  • subList(int, int):List<E>
    子集

工具:

  • listIterator():ListIterator<E>
  • listIterator(int):ListIterator<E>
  • Collections.unmodifiableList(List<? extends T>):List<T>
    唯讀模式封裝
  • Collections.synchronizedList(List<T>):List<T>
    安全執行緒封裝

 

ArrayList

父類:List,Collection

改:

  • ensureCapacity(int)
  • trimToSize()

 

LinkedList

父類:List,Deque,Queue,Connection

特徵:鏈式儲存

 

Vector

父類:List,Collection

子類:Stack

特徵:安全執行緒

增:

  • addElement(E)
  • insertElementAt(E, int)

刪:

  • removeAllElements()
  • removeElement(Object):boolean
  • removeElementAt(int)

改:

  • setElementAt(E, int)
  • setSize(int)
  • ensureCapacity(int)
  • trimToSize()

查:

  • firstElement():E
  • lastElement():E
  • elementAt(int):E
  • elements():Enumeration<E>
  • indexOf(Object, int):int
  • lastIndexOf(Object, int):int
  • capacity():int
  • copyInto(Object[])

 

Stack

父類:Vector,List,Collection

特徵:安全執行緒;先入後出

增:

  • push(E):E

刪:

  • pop():E

改:

  • peek():E
  • search(Object):int
  • empty():boolean

 

(Abstract+)

Queue

父類:Collection

子類:Deque,ConcurrentLinkedQueue,BlockingQueue,LinkedList

增:

  • offer(E):boolean

刪:

  • poll():E
  • remove():E

查:

  • peek():E
  • element():E

 

ConcurrentLinkedQueue

父類:Queue,Collection

特徵:鏈式儲存;安全執行緒;先進先出

 

BlockingQueue

父類:Queue,Collection

子類:ArrayBlockingQueue,LinkedBlockingQueue,PriorityBlockingQueue,DelayQueue,

SynchronousQueue,TransferQueue,LinkedTransferQueue,BlockingDeque

增:

  • offer(E, long, TimeUnit):boolean
  • put(E)

刪:

  • poll(long, TimeUnit):E
  • take():E
  • drainTo(Collection<? super E>):int
  • drainTo(Collection<? super E>, int):int

查:

  • remainingCapacity():int

 

ArrayBlockingQueue

父類:BlockingQueue,Queue,Collection

特徵:安全執行緒;先進先出;隊滿時阻塞進隊線程;隊空時阻塞出隊線程;

 

LinkedBlockingQueue

父類:BlockingQueue,Queue,Collection

特徵:鏈式儲存;安全執行緒;先進先出;隊滿時阻塞進隊線程;隊空時阻塞出隊線程;

 

PriorityBlockingQueue

父類:BlockingQueue,Queue,Collection

特徵:安全執行緒;策略排序;隊空時阻塞出隊線程;

查:

  • comparator():Comparator<? super E>

 

DelayQueue<E extends Delayed>

父類:BlockingQueue,Queue,Collection

特證:安全執行緒;策略排序;隊空時或隊頭未到期時,阻塞出隊線程;

 

SynchronousQueue

父類:BlockingQueue,Queue,Collection

特徵:安全執行緒;先進後出;元素進隊(put)後,阻塞進隊線程,至元素出隊為止;隊空時阻塞出隊線程;

 

TransferQueue

父類:BlockingQueue,Queue,Collection

子類:LinkedTransferQueue

增:

  • transfer(E)
  • tryTransfer(E):boolean
  • tryTransfer(E, long, TimeUnit):boolean

查:

  • getWaitingConsumerCount():int
  • hasWaitingConsumer():boolean

 

LinkedTransferQueue

父類:TransferQueue,BlockingQueue,Queue,Collection

特徵:安全執行緒;先進先出;元素進隊(transfer)後,阻塞進隊線程,至元素出隊為止;隊空時阻塞出隊線程;

 

Deque

父類:Queue,Collection

子類:ArrayDeque,BlockingDeque,LinkedList

增:

  • addFirst(E)
  • addLast(E)
  • offerFirst(E):boolean
  • offerLast(E):boolean
  • push(E):void

刪:

  • removeFirst():E
  • removeLast():E
  • removeFirstOccurrence(Object):boolean
  • removeLastOccurrence(Object):boolean
  • pollFirst():E
  • pollLast():E
  • pop():E

查:

  • getFirst():E
  • getLast():E
  • peekFirst():E
  • peekLast():E

工具:

  • descendingIterator():Iterator<E>

 

ArrayDeque

父類:Deque,Queue,Collection

 

BlockingDeque

父類:Deque,BlockingQueue,Queue,Collection

子類:LinkedBlockingDeque

增:

  • offerFirst(E, long, TimeUnit):boolean
  • offerLast(E, long, TimeUnit):boolean
  • putFirst(E)
  • putLast(E)

刪:

  • pollFirst(long, TimeUnit):E
  • pollLast(long, TimeUnit):E
  • takeFirst():E
  • takeLast():E

 

LinkedBlockingDeque

父類:BlockingDeque,BlockingQueue,Deque,Queue,Collection

 

(Abstract+)

Set

父類:Collection

子類:HashSet,TreeSet,SortedSet,NavigableSet,EnumSet

特徵:代表不可重複序列

工具:

  • Collections.unmodifiableSet(Set<? extends T>):Set<T>
    唯讀模式封裝
  • Collections.synchronizedSet(Set<E>):Set<E> 
    安全執行緒封裝

 

HashSet

父類:Set,Collection

子類:LinkedHashSet

特徵:不可重複;策略排序(雜湊表演算法),一般代表無序

 

LinkedHashSet

父類:HashSet,Set,Collection

特徵:不可重複;保留加入序

 

SortedSet

父類:Set,Collection

子類:TreeSet,NavigableSet

特徵:代表有序

查:

  • first():E
  • last():E
  • headSet(E):SortedSet<E>
  • tailSet(E):SortedSet<E>
  • subSet(E, E):SortedSet<E>
  • comparator():Comparator<? super E>

工具:

  • Collections.synchronizedSortedSet(SortedSet<T>):SortedSet<T>
    安全執行緒封裝
  • Collections.unmodifiableSortedSet(SortedSet<T>):SortedSet<T>
    唯讀模式封裝

 

NavigableSet

父類:SortedSet,Set,Collection

子類:TreeSet

特徵:提供進階操作

刪:

  • pollFirst():E
  • pollLast():E

查:

  • ceiling(E):E
  • floor(E):E
  • higher(E):E
  • lower(E):E
  • headSet(E, boolean):NavigableSet<E>
  • tailSet(E, boolean):NavigableSet<E>
  • subSet(E, boolean, E, boolean):NavigableSet<E>
  • descendingSet():NavigableSet<E>

工具:

  • descendingIterator():Iterator<E>
  • Collections.unmodifiableNavigableSet(NavigableSet<T>):NavigableSet<T>
    唯讀模式封裝
  • Collections.synchronizedNavigableSet(NavigableSet<T>):NavigableSet<T>
    安全執行緒封裝

 

TreeSet

父類:NavigableSet,SortedSet,Set,Collection

特徵:不可重複;策略排序(紅/黑樹狀結構演算法);不能有空元素

 

EnumSet<E extends Enum<E>>

父類:Set,Collection

特徵:用於枚舉類型

構建:

  • s+allOf(Class<E>):ElemSet<E>
    全集
  • s+noneOf(Class<E>):ElemSet<E>
    空集
  • s+copyOf(Collection<E>):ElemSet<E>
  • s+copyOf(EnumSet<E>):ElemSet<E>
  • s+complementOf(EnumSet<E>):ElemSet<E>
    補集
  • s+of(E...):ElemSet<E>
  • s+range(E, E):ElemSet<E>

 

待續更新!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.