title: Maximum Size List in Java
body: <p>It's useful to me to have a data structure in Java that has all the functionality of a List, but has a maximum storage capacity, and drops older data when newer data is added. Conceivably at some point I might want to implement a fixed size Queue which keeps a more general ordering of the data, and drops the old data lowest in that ordering, but that's the for the future.</p>
  
  <p>At the moment I'm implementing it like this:</p>
  
  <pre><code>public class FixedSizeList&lt;T&gt; {
  
    private final int maxSize;
    private final LinkedList&lt;T&gt; list = new LinkedList&lt;T&gt;();
  
    public FixedSizeQueue(int maxSize) {
      this.maxSize = maxSize &lt; 0 ? 0 : maxSize;
    }
  
    public T add(T t) {
      list.add(t);
      return list.size() &gt; maxSize ? list.remove() : null;
    }
  
    // add remaining methods...
  
  }
  </code></pre>
  
  <p>Is there either (a) an existing data structure that serves my needs, or (b) a better way of implementing this data structure?</p>