Java examples for java.nio:ByteBuffer Float
list of float to ByteBuffer
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.List; public class Main { public static void main(String[] argv) throws Exception { List arr = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(list2ByteBuffer(arr)); }/* w ww . j a v a 2 s.c o m*/ public static ByteBuffer list2ByteBuffer(List<Float> arr) { ByteBuffer ibb = ByteBuffer.allocateDirect(arr.size() * 4); ibb.order(ByteOrder.nativeOrder()); FloatBuffer fbb = ibb.asFloatBuffer(); for (float f : arr) { fbb.put(f); } //?????? ibb.position(0); return ibb; } }