allocate Int Buffer - Java java.nio

Java examples for java.nio:IntBuffer

Description

allocate Int Buffer

Demo Code


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

import java.nio.IntBuffer;

public class Main {
    public static void main(String[] argv) throws Exception {
        int numInts = 2;
        System.out.println(allocateIntBuffer(numInts));
    }//from w w  w. j  a va2s . c o m

    public static IntBuffer allocateIntBuffer(int numInts) {
        ByteBuffer bb;
        int allocationSize = 4 * numInts;
        bb = ByteBuffer.allocateDirect(allocationSize);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        return bb.asIntBuffer();
    }
}

Related Tutorials