Possible Duplicate:
Size-limited queue that holds last N elements in Java
Does java include a native class which allows a maximum number of elements and if I input one element more, it automatically removes an old one (e.g. based on natural sorting)?
If not, I can write it myself of course, but I just wanted to ask.
There are lots.
You can use a Queue, and specify a fixed length. Implement your own using an ArrayList that removes element 0 every time a new element is added that increases the size past your limit.
A popular technique is to make a
queuewith a LinkedHashMap