Java examples for java.nio:FloatBuffer
Allocates a FloatBuffer with the given length.
//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 length = 2; System.out.println(allocateFloatBuffer(length)); }//from ww w.j av a2 s . c o m /** * Allocates a FloatBuffer with the given length. * * @param length The length of the buffer to allocate (in elements, not bytes!). * @return The newly allocated buffer. */ public static FloatBuffer allocateFloatBuffer(int length) { return ByteBuffer.allocateDirect(length * 4) // float == 4 bytes .order(ByteOrder.nativeOrder()).asFloatBuffer(); } }