Share on Google+Share on Google+

How to rewind float buffer in java.

Advertisement
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

Advertisements

Posted on: August 2, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.