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

 
 

Share on Google+Share on Google+
How to rewind float buffer in java.
Posted on: August 2, 2010 at 12:00 AM
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

Advertisement

Related Tags for How to rewind 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: August 2, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com