Share on Google+Share on Google+

How to transfer data from int buffer to int array.

Advertisement
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

Advertisements

Advertisement

Posted on: August 4, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.