How to transfer data from int buffer to int array.


 

How to transfer data from int buffer to int array.

In this tutorial you will see how to transfer data from int buffer to int array.

In this tutorial you will see how to transfer data from int buffer to int array.

How to transfer data from int buffer to int array.

 In this tutorial, we will discuss how to transfer data from int buffer to int array.

IntBuffer API:

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

Return type Method Description
static IntBuffer wrap(int[] array)   The wrap() method create a int buffer by wrapping the associated int array.
IntBuffer get(int[] array) The get(...) method transfer int from associated buffer into int array.

Code

import java.nio.*;
import java.nio.IntBuffer;
public class TransferToArray {
  public static void main(String[] argv){
    int[] array = new int[] { 754};
    IntBuffer intBuf = IntBuffer.wrap(array);
    int[] arr = new int[intBuf.limit()];
    intBuf.get(arr);
System.out.println("Content transfer from buffer to array.");
    for (int i = 0; i < arr.length; i++)
      System.out.println(arr[i]);
  }
}

Output

C:\>java TransferToArray
Content transfer from buffer to array.
7
5
4
3

Download this code

Ads