In
this tutorial, we will discuss how to get value of a given index from buffer. The ByteBuffer
class
is a container for handling data. The get(int index) method of ByteBuffer class
returns value
of a given index. The method allocate( int capacity)
creates a new byte buffer, and the current position
will be
zero and its limit will be it's capacity.
About ByteBuffer API:
The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides the following methods:
| Return type | Method | Description |
| static ByteBuffer | allocate( int capacity) | The allocate() method create a byte buffer of specified capacity. |
| byte | get(int index) | The get() method reads bytes at given index from buffer. |
import java.io.*;
|
output
| C:\Work\Bharat\load\getSpecified value>java GetIndexValue Value in first buffer at index 4 : r Value in second buffer at index 4 : a |