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 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.