Java Buffer.rewind()

Syntax

Buffer.rewind() has the following syntax.

public final Buffer rewind()

Example

In the following code shows how to use Buffer.rewind() method.


import java.nio.ByteBuffer;
//from  w ww.j  a  v a  2 s  . com
public class Main {
  public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();
    System.out.println("Byte Buffer");
    while (bb.hasRemaining())
      System.out.println(bb.position() + " -> " + bb.get());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio »




Buffer
ByteBuffer
ByteOrder
CharBuffer
DoubleBuffer
FloatBuffer
IntBuffer
LongBuffer
MappedByteBuffer
ShortBuffer