Home Tutorial Java Corejava Nio How to allocate a float buffer in java.

 
 

Share on Google+Share on Google+
How to allocate a float buffer in java.
Posted on: July 29, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for How to allocate a float buffer in java.:


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.

Posted on: July 29, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com