Home Tutorial Java Corejava Nio Create a short buffer by using wrap method of ShortBuffer class.

 
 

Share on Google+Share on Google+
Create a short buffer by using wrap method of ShortBuffer class.
Posted on: August 11, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Create a short buffer by using wrap method of ShortBuffer class.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 11, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com