What is the most computationally efficient way to retrieve the last item in Apache circularfifobuffer? Last as in the latest to be added.
The only way I can see is to cycle through the whole buffer with .remove()
or .iterator.next()
. (The latter in conjunction with .size
.) Is there a more efficient way? And with .iterator
, will the order in which items are entered the buffer be preserved? For example, suppose I am interested in the 2nd latest item in a buffer with 10 items. Will calling .iterator.next()
9 times reliably accomplish the task?
I am new to Java. Please bear with me on what is probably an obvious question to others. Thank you.