Size-limited queue that holds last N elements in Java

后端 未结 8 1396
灰色年华
灰色年华 2020-11-22 13:13

A very simple & quick question on Java libraries: is there a ready-made class that implements a Queue with a fixed maximum size - i.e. it always allows addi

8条回答
  •  有刺的猬
    2020-11-22 13:33

    The only thing I know that has limited space is the BlockingQueue interface (which is e.g. implemented by the ArrayBlockingQueue class) - but they do not remove the first element if filled, but instead block the put operation until space is free (removed by other thread).

    To my knowledge your trivial implementation is the easiest way to get such an behaviour.

提交回复
热议问题