开发者

Determine Number of Elements in a FloatBuffer

FloatBuffer has the method capacity() which tells us the maximum capacity of the Fl开发者_如何学JAVAoatBuffer. 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.


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...)


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.


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().


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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜