Java DoubleBuffer create from double array

Description

Java DoubleBuffer create from double array


import java.nio.DoubleBuffer;
import java.util.Arrays;

public class Main {
  public static void main(String[] argv) throws Exception {
    double[] doubleArray = new double[] { 1.1, 2.2, 3.3, 4.4, 5.5, };
    DoubleBuffer bb = DoubleBuffer.wrap(doubleArray);

    doubleArray = toArray(bb);/*from   www. j  ava  2  s. c o  m*/

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

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



PreviousNext

Related