Java FloatBuffer compare with ByteBuffer for byte content

Description

Java FloatBuffer compare with ByteBuffer for byte content

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

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

      FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
      System.out.println("Float Buffer");
      while (fb.hasRemaining())
         System.out.println(fb.position() + " -> " + fb.get());
   }
}



PreviousNext

Related