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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// toString() method
  
import java.nio.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // creating Shortbuffere
        ShortBuffer bb = ShortBuffer.allocate(100);
        bb.put((short)20);
        bb.put((short)30);
        // using toString method
        System.out.println(bb.toString());
    }
}

chevron_right


Output:

java.nio.HeapShortBuffer[pos=2 lim=100 cap=100]

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// toString() method
  
import java.nio.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // creating Shortbuffere
        ShortBuffer bb = ShortBuffer.allocate(300);
        bb.put((short)20);
        bb.put((short)30);
        bb.rewind();
        // using toString method
        System.out.println(bb.toString());
    }
}

chevron_right


Output:

java.nio.HeapShortBuffer[pos=0 lim=300 cap=300]

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.