Java ShortBuffer create from short array

Description

Java ShortBuffer create from short array

import java.nio.ShortBuffer;
import java.util.Arrays;

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

    shortArray = toArray(bb);//from   w ww.ja va  2 s .  c om

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

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



PreviousNext

Related