search

Home  >  Q&A  >  body text

java - JDK里为什么LinkedList实现了Deque,而ArrayList却没实现?

可以看到LinkedList implements Deque, 而ArrayList却没有。
另外还有一个ArrayDeque类。

为什么不让List接口继承Deque呢?

伊谢尔伦伊谢尔伦2787 days ago969

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 11:43:37

    Deque inherits from Queue. In fact, just think that List does not inherit from Queue. It is true that List can easily use remove(Object o) to implement Queue's remove(), but it is generally not designed this way because their meanings are different. Whether to use List to implement Queue is left to the specific class to decide. The answer for LinkedList is yes, and for ArrayList it is no.

    As for why ArrayList did not implement Queue, this is because ArrayList itself is just a List covered in Array skin. It is not recommended to insert new data from the top, otherwise the efficiency will be extremely poor. .

    ArrayDeque is a textbook deque implementation, and its existence is not controversial.

    reply
    0
  • Cancelreply