pushWithLimit method

void pushWithLimit(
  1. E element,
  2. int limit
)

Adds element to this list and pops an element to keep the total length within limit.

Implementation

void pushWithLimit(E element, int limit) {
  if (length >= limit) removeFirst();
  addLast(element);
}