int Array To IntBuffer - Android java.nio

Android examples for java.nio:IntBuffer

Description

int Array To IntBuffer

Demo Code


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

import java.nio.IntBuffer;

public class Main {
    public static IntBuffer intArrayToBuffer(int[] intArray) {
        ByteBuffer byteBuffer = ByteBuffer
                .allocateDirect(intArray.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        IntBuffer intBuffer = byteBuffer.asIntBuffer();
        intBuffer.put(intArray);/*from www  .  j a  v a 2 s .c  o m*/
        intBuffer.position(0);
        return intBuffer;
    }
}

Related Tutorials