ShortBuffer toString() method in Java with Examples
The toString() method in java.nio.ShortBuffer is used to return a string summarizing the state of this buffer. Syntax:
public String toString()
Return Value:The method returns a summary string. Below are the examples to illustrate the toString() method: Program 1:
Java
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
ShortBuffer bb = ShortBuffer.allocate( 100 );
bb.put(( short ) 20 );
bb.put(( short ) 30 );
System.out.println(bb.toString());
}
}
|
Output:
java.nio.HeapShortBuffer[pos=2 lim=100 cap=100]
Program 2:
Java
import java.nio.*;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
ShortBuffer bb = ShortBuffer.allocate( 300 );
bb.put(( short ) 20 );
bb.put(( short ) 30 );
bb.rewind();
System.out.println(bb.toString());
}
}
|
Output:
java.nio.HeapShortBuffer[pos=0 lim=300 cap=300]
Last Updated :
13 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...