Write a float value into float buffer at given index.


 

Write a float value into float buffer at given index.

In this tutorial you will see how write a float value into float buffer at given index.

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

Ads