Share on Google+Share on Google+

How to allocate a float buffer in java.

In this tutorial you will see how to allocate a float buffer in java.

How to allocate a float buffer in java.

 In this tutorial, we will see how to allocate a new float buffer.

FloatBuffer API:

The java.nio.FloatBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
static FloatBuffer allocate( int capacity)  The allocate() method allocate a float buffer of given capacity. 
int limit() The limit() method returns the limit of  float buffer.
int position() The position() method returns the position of float buffer.
final int capacity() The capacity() method returns the capacity of associated float buffer.


import java.nio.*;
import java.nio.FloatBuffer;
public class FloatBufferDemo {
public static void main(String[] argsthrows Exception {
FloatBuffer floatBuf = FloatBuffer.allocate(500);
System.out.println("Position of FloatBuffer :" 
                                  + floatBuf.position
System.out.println("Limit of FloatBuffer :" 
                                     + floatBuf.limit());
System.out.println("Capacity of FloatBuffer :"
+ floatBuf.capacity());


C:\>java FloatBufferDemo
Position of FloatBuffer :0
Limit of FloatBuffer :500
Capacity of FloatBuffer :500

Download this code



Posted on: July 29, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null