Java ShortBuffer convert to short array

Description

Java ShortBuffer convert to 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 . j a  v  a2 s. co  m

    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