Creates a duplicate float buffer that shares the content of float buffer.


 

Creates a duplicate float buffer that shares the content of float buffer.

In this tutorial you will see how to create a duplicate float buffer that shares the content of float buffer.

In this tutorial you will see how to create a duplicate float buffer that shares the content of float buffer.

Creates a duplicate float buffer that shares the content of float buffer.

In this tutorial, we will see how to create a duplicate float buffer that shares the content of old buffer.

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 new byte buffer.
abstract FloatBuffer duplicate() The duplicate() method returns a  duplicate buffer that share the content of available buffer.

Code

import java.nio.*;
import java.nio.FloatBuffer;

public class FloatDuplicate {
public static void main(String[] args){
FloatBuffer floatBuf = FloatBuffer.allocate(1024);
    floatBuf.put(12.061f);
    floatBuf.put(13.072f);
    floatBuf.put(14.083f);
    floatBuf.flip();
System.out.println("Content in original buffer.");
    while (floatBuf.hasRemaining()) {
      System.out.println(floatBuf.get());
    }
    FloatBuffer f = floatBuf.duplicate();
    f.flip();
System.out.println("Content in duplicate buffer.");
    while (f.hasRemaining()) {
      System.out.println(f.get());
    }
  }
}

Output

C:\e>java FloatDuplicate
Content in original buffer.
12.061
13.072
14.083
Content in duplicate buffer.
12.061
13.072
14.083

Download this code

Ads