Java IntBuffer create from int array

Description

Java IntBuffer create from int array

import java.nio.IntBuffer;
import java.util.Arrays;

public class Main {
  public static void main(String[] argv) throws Exception {
    int[] intArray = new int[] { 3, 5, 6, 7, 8, 4 };
    IntBuffer bb = IntBuffer.wrap(intArray);

    intArray = toArray(bb);//from w w  w  .  j  av  a2s .c o  m

    System.out.println(Arrays.toString(intArray));
  }

  public static int[] toArray(final IntBuffer buffer) {
    int[] array = new int[buffer.limit()];
    buffer.get(array);
    return array;
  }

}



PreviousNext

Related