Java IntBuffer convert to int array

Description

Java IntBuffer convert to 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 a  v a2  s  .  com

    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