Java examples for java.nio:IntBuffer
make IntBuffer
//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[] arr = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(makeIntBuffer(arr)); }/* ww w .j av a 2s. c o m*/ public static IntBuffer makeIntBuffer(int[] arr) { ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); IntBuffer Ib = bb.asIntBuffer(); Ib.put(arr); Ib.position(0); return Ib; } public static IntBuffer makeIntBuffer(int size) { ByteBuffer bb = ByteBuffer.allocateDirect(size * 4); bb.order(ByteOrder.nativeOrder()); IntBuffer Ib = bb.asIntBuffer(); Ib.position(0); return Ib; } }