简体   繁体   English

ArrayDeque: addLast(E) + removeLast() 和 push(E) / pop() 一样吗? 更喜欢 addFirst(E) + removeFirst() 有什么好处吗?

[英]ArrayDeque: addLast(E) + removeLast() would be same as push(E) / pop()? Does preferring addFirst(E) + removeFirst() have any advantages?

ArrayDeque docs state that push(E) is same as addFirst(E) , and pop() is same as removeFirst() . ArrayDeque 文档指出push(E)addFirst(E)相同, pop()removeFirst()相同。

I think the same effect could be achieved with addLast(E) + removeLast() pair of methods.我认为使用addLast(E) + removeLast()对方法可以实现相同的效果。

  1. Is that right ?是对的吗 ?
  2. Does preferring addFirst(E) + removeFirst() have any advantages?更喜欢addFirst(E) + removeFirst()有什么好处吗?

The methods are summarised in the Deque interface.这些方法总结在Deque接口中。 If you are using the ArrayDeque as a Queue use that interface, otherwise use the Deque methods.如果您将ArrayDeque用作Queue使用该接口,否则使用Deque方法。 I's kind of unfortunate that Deque extends Queue as it is a Queue equally in four different obvious ways.我有点不幸的是, Deque扩展了Queue因为它以四种不同的明显方式同样是一个Queue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM