List.of( array )
You can pass an array to List.of
resulting in a non-modifiable List
with a fixed size of the array’s size. Elements cannot be added, removed, or replaced.
Object[] arr = new Object[100] ;
… populate array
List< Object > objs = List.of( arr ) ;
Circular buffer (a.k.a. cyclic buffer, or ring buffer)
Or, perhaps you want a non-blocking queue which automatically evicts elements from the head of the queue when attempting to add new elements onto the queue and it is full.
If so, see my Answer on the Question, Is there a fixed sized queue which removes excessive elements?. There I mention EvictingQueue
from Google Guava, and CircularFifoQueue
from Apache Commons.
To instantiate an EvictingQueue
call the static factory method create
and specify your maximum size.
EvictingQueue< Person > people = com.google.common.collect.EvictingQueue.create( 100 ) ; // Set maximum size to 100.