[英]Why fill() , copy() ,reverse() and shuffle() of Collections in java is implemented this way
[英]Why fill, copy (dstList, srcList), shuffle, reverse, rotate Collections class methods take only List as argument?
這背后是否有明確的邏輯:在Collections類中,以下方法僅將List作為參數
填充,復制(dstList,srcList),shuffle,reverse,rotate
例如,這些方法也可以采用Queue,Deque。
好吧,這個方法不能接受任何Collection
,因為有些Collection
沒有排序(這意味着像reverse
或shuffle
這樣的方法沒有意義)或者不允許重復(這意味着像fill
和nCopies
類的方法沒有意義) 。
雖然Queue
和Dequeue
具有排序和允許重復,但是這些Collection
的元素應該按照與添加它們的順序相關的特定順序(FIFO或LIFO)使用,因此像shuffle
這樣的方法可能shuffle
意義。
但是,您可以使用LinkedList
,它實現List
和Deque
以在隊列上調用這些方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.