title: Size-limited queue that holds last N elements in Java
body: <p>A very simple &amp; quick question on Java libraries: is there a ready-made class that implements a <code>Queue</code> with a fixed maximum size - i.e. it always allows addition of elements, but it will silently remove head elements to accomodate space for newly added elements.</p>
  
  <p>Of course, it's trivial to implement it manually:</p>
  
  <pre><code>import java.util.LinkedList;
  
  public class LimitedQueue&lt;E&gt; extends LinkedList&lt;E&gt; {
      private int limit;
  
      public LimitedQueue(int limit) {
          this.limit = limit;
      }
  
      @Override
      public boolean add(E o) {
          super.add(o);
          while (size() &gt; limit) { super.remove(); }
          return true;
      }
  }
  </code></pre>
  
  <p>As far as I see, there's no standard implementation in Java stdlibs, but may be there's one in Apache Commons or something like that?</p>