Queue vs List

前端 未结 4 825
陌清茗
陌清茗 2020-12-13 12:41

I\'m currently using a List as a queue (use lst[0] then lst.removeAt(0)) to hold objects. There\'s about 20 items max at a g

4条回答
  •  爱一瞬间的悲伤
    2020-12-13 13:05

    Besides the fact that the Queue class implements a queue and the List class implement a list there is a performance difference.

    Every time you remove the first element from List all elements in the queue are copied. With only 20 elements in the queue it may not be noticeable. However, when you dequeue the next element from Queue no such copying is happening and that will always be faster. If the queue is long the difference can be significant.

提交回复
热议问题