Reputation:
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.
Upvotes: 4
Views: 4953
Reputation: 310
For debugging purpose just use
floatBuffer.toString()
At the end of the string the informations about the current position and the capacity will be shown, like
...[pos=0 lim=1024 cap=1024]
Upvotes: 0
Reputation: 456
So how can I determine the number of elements in a FloatBuffer?
Wouldn't it just be the position() ?
To determine if you can write more to it, just test for fb.remaining() > 0 or fb.hasRemaining().
Upvotes: 0
Reputation: 1187
You can't. As with an array of floats you can get the length but which ones have been set is determined by the application.
Upvotes: 2
Reputation: 1500983
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...)
Upvotes: 8