Create a short buffer by using wrap method of ShortBuffer class.


 

Create a short buffer by using wrap method of ShortBuffer class.

In this tutorial, you will see how to create a short buffer by using wrap method of ShortBuffer class.

In this tutorial, you will see how to create a short buffer by using wrap method of ShortBuffer class.

Create a short buffer by using wrap method of ShortBuffer class.

In this tutorial, we will see how to create a shortt buffer by using wrap method of ShorttBuffer class.

ShortBuffer API.

The java.nio.ShortBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
static ShortBuffer wrap(short[] array)  The wrap() method create a short buffer by wrapping  the associated short array. 
abstract short get() The get() method read short value from current position and increment position..

Code

import java.nio.*;
import java.nio.ShortBuffer;

public class WrapShortBuffer  {
  public static void main(String[] arg) {
    short[] array = new short[] { 123456 };
ShortBuffer shortBuff = ShortBuffer.wrap(array);
System.out.println("Limit of short buffer : " 
                            + shortBuff.limit());
System.out.println("capacity of short buffer : " 
                         + shortBuff.capacity());
  System.out.println("Content in shortbuffer.");
    while (shortBuff.hasRemaining()) {
      System.out.print(shortBuff.get() " ");
    }
  }
}

Output

C:\>java WrapShortBuffer
Limit of short buffer : 3
capacity of short buffer : 3
Content in shortbuffer.
12 34 56

Download this code

Ads