In this tutorial, we will check buffer is direct or not.
The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides the following methods:
| Return type | Method | Description |
| abstract boolean | isDirect() | The isDirect() method tells whether this associated buffer is direct or not. |
| static ByteBuffer | wrap(byte[] array) | The wrap(...) method create a byte buffer by wrapping the associated byte array. |
| static ByteBuffer | allocate( int capacity) | The allocate() method allocate a byte buffer. |
| static ByteBuffer | allocateDirect( int capacity) | The allocateDirect()method allocate a direct byte buffer. |
import java.nio.*;
|
| C:\>java BufferIsDirect ByteBuffer not direct allocated ByteBuffer not direct allocated ByteBuffer direct allocateed |