Share on Google+Share on Google+

Use of toString() method of FloatBuffer class.

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

Use of toString() method of FloatBuffer class.

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

FloatBuffer API:

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

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


import java.nio.*;
import java.nio.FloatBuffer;
  class FlBufferToString {
  public static final int capacity = 512;
  public static void main(String[] arg) {
    FloatBuffer fBuffer = FloatBuffer.allocate(capacity);
    System.out.println("Information of float buffer.");
    System.out.println("Position : " + fBuffer.position());
    System.out.println("Limit : " + fBuffer.limit());
    System.out.println("Capacity : " + fBuffer.capacity());
System.out.println("String representation of the float buffer state.");


C:\>java FlBufferToString
Information of float buffer.
Position : 2
Limit : 512
Capacity : 512
String representation of the float buffer state.
java.nio.HeapFloatBuffer[pos=2 lim=512 cap=512]

Download this code



Posted on: August 2, 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.


Advertisement null