float Array To FloatBuffer - Android java.nio

Android examples for java.nio:FloatBuffer

Description

float Array To FloatBuffer

Demo Code


//package com.book2s;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Main {
    public static FloatBuffer floatArrayToBuffer(float[] floatArray) {
        ByteBuffer byteBuffer = ByteBuffer
                .allocateDirect(floatArray.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
        floatBuffer.put(floatArray);/*ww w . jav a 2s .  c  o m*/
        floatBuffer.position(0);
        return floatBuffer;
    }
}

Related Tutorials