How to rewind float buffer in java.


 

How to rewind float buffer in java.

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

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

How to rewind float buffer in java.

In this tutorial, we will see how to rewind float buffer in java.

In this example, The rewind method reset the position of buffer at zero. So you can again 
read the buffer.

Code

import java.nio.*;
import java.nio.FloatBuffer;

public class RewindFloatBuffer{
  public static void main(String[] args) {
    FloatBuffer floatBuf = FloatBuffer.allocate(55);
    floatBuf.put(4.8f);
    floatBuf.put(3.9f);
    floatBuf.put(5.6f);
    floatBuf.flip();
    System.out.print("Data in float buffer.\n");
    for (int i = 0; i < floatBuf.limit(); i++) {
      System.out.println(floatBuf.get());
    }
    floatBuf.rewind();
    System.out.print("After rewind method data in float buffer.\n");
    for (int i = 0; i < floatBuf.limit(); i++) {
      System.out.println(floatBuf.get());
    }
  }
}

Output

C:\r>java RewindFloatBuffer
Data in float buffer.
4.8
3.9
5.6
After rewind method data in float buffer.
4.8
3.9
5.6

Download this code

Ads