Kotlin program snippet:
fun peek() = if (!elements.isEmpty() && elements.size > 0) elements[0] else null
It works great, but sometimes I get a firebase crash report:
Fatal Exception: java.lang.IndexOutOfBoundsException Index: 0, Size: 1 java.util.ArrayList.get (ArrayList.java:437) bigmick.ghu.util.Queue.peek (Queue.kt:17)
For me it sounds crazy: the list's size is 1, also the first (existing) element can be referred by index=0.
As far as I know it should work. But sometimes it does not.