Web / Apache Commons Collections Interview questions
Define CircularFifoQueue in Apache Commons Collections?
CircularFifoQueue<E> is a fixed-capacity Queue implementation backed by an array that behaves like a circular buffer: once it's full, adding a new element automatically discards the oldest one instead of throwing an exception.
CircularFifoQueue<Integer> buffer = new CircularFifoQueue<>(3); buffer.add(1); buffer.add(2); buffer.add(3); buffer.add(4); // 1 is silently evicted System.out.println(buffer); // [2, 3, 4]
This makes it a good fit for use cases like keeping the "last N log lines," a rolling metrics window, or a recent-history buffer, where you always want a bounded, most-recent view without manual eviction logic.
More Related questions...