Home Tutorial Java Corejava Nio How to read all value from int buffer in java.

 
 

Share on Google+Share on Google+
How to read all value from int buffer in java.
Posted on: August 3, 2010 at 12:00 AM
Advertisement
In this tutorial you will see how to read all value from int buffer in java.

How to read all value from int buffer in java.

In this tutorial, we will discuss how to read all value from int buffer in java.

 IntBuffer API:

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

Return type Method Description
static IntBuffer allocate( int capacity)  The allocate() method create a int buffer of specified capacity. 
int get() The get() method read int value from current position of int buffer.

Code

import java.nio.*;
import java.nio.IntBuffer;
public class ReadAll {
  public static void main(String[] arg) {
    int[] array=new int[]{7,5,4,3};
    IntBuffer intBuf = IntBuffer.wrap(array);
    while (intBuf.hasRemaining()) 
    {
System.out.println(intBuf.get());      
    } 
  }
}

Output

C:\>java ReadAll
7
5
4
3

Download this code

Advertisement

Related Tags for How to read all value from int buffer in java.:


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

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com