Java ByteBuffer wrap byte array and rewind to loop again

Description

Java ByteBuffer wrap byte array and rewind to loop again

import java.nio.ByteBuffer;

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();/*from  w w w . j a  v a2 s  .  co m*/
      System.out.println("Byte Buffer");
      while (bb.hasRemaining())
         System.out.println(bb.position() + " -> " + bb.get());


   }
}



PreviousNext

Related