Java LongBuffer create from long array

Description

Java LongBuffer create from long array

import java.nio.LongBuffer;
import java.util.Arrays;

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

    longArray = toArray(bb);//  w ww . j  a va 2  s .com

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

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

}



PreviousNext

Related