Home Tutorial Java Corejava Nio Use of rewind() method of FloatBuffer class.

 
 

Share on Google+Share on Google+
Use of rewind() method of FloatBuffer class.
Posted on: July 29, 2010 at 12:00 AM
Advertisement
In this tutorial you will see the use of rewind method of FloatBuffer class..

Use of rewind() method in float buffer class.

In this tutorial, we will see the Use of rewind method of FloatBuffer class.

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.
final boolean hasRemaining() The hasRemaining() method tell whether there are any elements in buffer or not.
final Buffer rewind() The rewind() method set the position zero and content not change.

   Code

import java.nio.*;
import java.nio.FloatBuffer;
public class FloatBufferRewind {
  public static void main(String[] args) {
    FloatBuffer floatBuf = FloatBuffer.allocate(55);
    floatBuf.put(12.05f);
    floatBuf.put(21.90f);
    floatBuf.put(875.976f);
    floatBuf.put(34.09f);
    floatBuf.put(123.453f);
    floatBuf.flip();
  System.out.println("Contents in float buffer :");
    while (floatBuf.hasRemaining()) {
      System.out.print(floatBuf.get() ",");
    }
    System.out.println("\n");
    floatBuf.rewind();
    System.out
    .print("After using rewind method 
    content of float buffer : \n"
);
    while (floatBuf.hasRemaining()) {
      System.out.print(floatBuf.get() ",");
    }
  }
}

Output

C:\>java FloatBufferRewind
Contents in float buffer :
12.05,21.9,875.976,34.09,123.453
After using rewind method content of float buffer :
12.05,21.9,875.976,34.09,123.453,

Download this code

Advertisement

Related Tags for Use of rewind() method of FloatBuffer class.:


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

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com