Home Tutorial Java Corejava Nio Write a float value into float buffer at given index.

 
 

Share on Google+Share on Google+
Write a float value into float buffer at given index.
Posted on: July 31, 2010 at 12:00 AM
Advertisement
In this tutorial you will see how write a float value into float buffer at given index.

Write a float value into float buffer at given index.

 In this tutorial, we will see how to write the given float value into float buffer at the given index.

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 new float buffer.
abstract  FloatBuffer put(int index, float f) The put(..) method write the given float value into associated buffer at given index.
abstract  float get(int index) The get(...) method returns float value at given index.

Code

import java.nio.*;
import java.nio.FloatBuffer;
public class PutIndexValue {
  public static final int capacity = 256;
  public static final int index = 3;
  public static void main(String[] arg) {
    FloatBuffer f = FloatBuffer.allocate(capacity);
    f.put(index, 22.45f);
System.out.println("Store value at index : " + index);
    System.out.println(f.get(3));
  }
}

Output

C:\>java PutIndexValue
Store value at index : 3
22.45

Download this code

Advertisement

Related Tags for Write a float value into float buffer at given index.:


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 31, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com