Use of toString() method of FloatBuffer class.


 

Use of toString() method of FloatBuffer class.

In this tutorial you will see the 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.

Code

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);
    fBuffer.put(22.45f);
    fBuffer.put(2.45f);
    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.");
    System.out.println(fBuffer.toString());
  }
}

Output

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

Ads