Java ByteBuffer store float type array

Description

Java ByteBuffer store float type array

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

public class Main {

   public static void main(String[] args) {

      float[] floats = { 6.61E-39F, 9.91E-39F };

      ByteBuffer bb = ByteBuffer.allocate(floats.length * 4);

      FloatBuffer fb = bb.asFloatBuffer();
      fb.put(floats);/*  w  ww.j  av a2s. c  o  m*/

      CharBuffer cb = bb.asCharBuffer();
      System.out.println(cb.toString());

   }
}



PreviousNext

Related