allocate Float Buffer - Java java.nio

Java examples for java.nio:FloatBuffer

Description

allocate Float Buffer

Demo Code


//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 {
        int numFloats = 2;
        System.out.println(allocateFloatBuffer(numFloats));
    }//w  ww .  j  a  v a  2  s  .  c  o  m

    public static FloatBuffer allocateFloatBuffer(int numFloats) {
        ByteBuffer bb;
        int allocationSize = 4 * numFloats;
        bb = ByteBuffer.allocateDirect(allocationSize);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        return bb.asFloatBuffer();
    }
}

Related Tutorials