Java examples for java.nio:FloatBuffer
list of float to FloatBuffer
//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(list2FloatBuffer(arr)); }//from www. java 2s . co m public static FloatBuffer list2FloatBuffer(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); } //?????? fbb.position(0); return fbb; } }