Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * create a Floatbuffer for a given Array
     * @param array
     * @return
     */
    public static FloatBuffer createFloatBuffer(float[] array) {
        final int floatSize = Float.SIZE / 8;
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * floatSize);
        byteBuffer.order(ByteOrder.nativeOrder());
        FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
        floatBuffer.put(array);
        floatBuffer.position(0);
        return floatBuffer;
    }
}