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
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

Advertisement

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


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 4, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com