Home Tutorial Java Corejava Nio How to transfer data from int buffer to int array.

 
 

How to transfer data from int buffer to int array.
Posted on: August 4, 2010 at 12:00 AM
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

Related Tags for How to transfer data from int buffer to int array.:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.