Java examples for java.nio:FloatBuffer
make FloatBuffer
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; public class Main { public static void main(String[] argv) throws Exception { float[] arr = new float[] { 34.45f, 35.45f, 36.67f, 37.78f, 37.0000f, 37.1234f, 67.2344f, 68.34534f, 69.87700f }; System.out.println(makeFloatBuffer(arr)); }/*from ww w . ja v a 2 s .com*/ public static FloatBuffer makeFloatBuffer(float[] arr) { ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb; } public static FloatBuffer makeFloatBuffer(int size) { ByteBuffer bb = ByteBuffer.allocateDirect(size * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.position(0); return fb; } }