Share on Google+Share on Google+

ShortBuffer in java, Use of toString() method of ShortBuffer class.

In this tutorial, you will see the use of toString() method of ShortBuffer class.

Use of toString() method of ShortBuffer class.

In this tutorial, we will see how to represent the state of short buffer in the form of string.

ShortBuffer API:

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

Return type Method Description
static ShortBuffer allocate( int capacity)  The allocate(..) method allocate a short buffer of given capacity. 
abstract ShortBuffer toString() The toString() method returns a string that  summarizing the state of buffer.


import java.nio.*;
import java.nio.ShortBuffer;
public class StateString {
  public static final int index = 2;
  public static void main(String[] arg) {
    ShortBuffer shortBuff = ShortBuffer.allocate(1024);
    System.out.println("Position of short buffer : "
    System.out.println("Limit of short buffer : "
    System.out.println("capacity of short buffer : "
    System.out.println("String representation of"
" state of short buffer : ");


C:\>java StateString
Position of short buffer : 2
Limit of short buffer : 1024
capacity of short buffer : 1024
String representation of state of short buffer :
java.nio.HeapShortBuffer[pos=2 lim=1024 cap=1024]

Download this code


Posted on: August 12, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.