Java ByteBuffer store short type value via ShortBuffer and read

Description

Java ByteBuffer store short type value via ShortBuffer and read

import java.nio.ByteBuffer;

public class Main {
   private static final int BSIZE = 1024;

   public static void main(String[] args) {
      ByteBuffer bb = ByteBuffer.allocate(BSIZE);

      bb.rewind();//from  ww w .j a va2 s.co m
      // Store and read a short:
      bb.asShortBuffer().put((short) 1234);
      System.out.println(bb.getShort());

   }
}



PreviousNext

Related