Home Tutorial Java Corejava Nio Use of toString() method of FloatBuffer class.

 
 

Use of toString() method of FloatBuffer class.
Posted on: August 2, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Use of toString() method of FloatBuffer class.:


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.

Posted on: August 2, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com