Search code examples
javafloatbuffer

Determine Number of Elements in a FloatBuffer


FloatBuffer has the method capacity() which tells us the maximum capacity of the FloatBuffer. However, it does not tell us how many elements are in that buffer. So how can I determine the number of elements in a FloatBuffer? I am trying to determine if my FloatBuffer is full or partially full.


Solution

  • I can never keep the NIO buffer's straight in my head, but remaining() might be what you're after...

    Returns the number of elements between the current position and the limit.

    (Or just use hasRemaining() if you're after a simple Boolean...)