How to allocate a float buffer in java.


 

How to allocate a float buffer in java.

In this tutorial you will see 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.

Code

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());
  }
}

Output

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

Download this code

Ads