https://kotlinlang.org logo
Title
a

Ayfri

07/29/2022, 12:33 PM
Hi, is there a First In First Out collection in Kotlin which we can set a limited size ?
g

Giorgos Makris

07/29/2022, 12:44 PM
Have you looked into buffered `Channel`s? Not exactly a collection but it could be better. Otherwise you could try something like this but with an array implementation
a

AndreyVanDenHaag

07/29/2022, 1:19 PM
Queue is a good option (since there is no requirement for thread blocking in your question): https://docs.oracle.com/javase/tutorial/collections/implementations/queue.html
a

Ayfri

07/29/2022, 1:20 PM
I found out about
ArrayDeque
in the documentation, maybe it's what I need ? It's for storing little data classes with 100 maximum items to keep RAM consuption small
s

Shawn

07/29/2022, 2:46 PM
ArrayDeque is definitely what I’d use instead of the older Queue or LinkedList classes to implement this, but I don’t think there are any stdlib data structures with a capacity-based eviction policy built in