ByteBuffer isDirect() methods in Java with Examples
The isDirect() method of java.nio.ByteBuffer Class is used to tell whether or not this byte buffer is direct.
Syntax:
public abstract boolean isDirect()
Return Value: This method returns true if, and only if, this buffer is direct.
Below are the examples to illustrate the isDirect() method:
Examples 1:
// Java program to demonstrate // isDirect() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // defining and allocating ByteBuffer // using allocate() method ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4); // check the byteBuffer // using isDirect() method boolean val = byteBuffer.isDirect(); // checking the condition if (val) System.out.println("buffer is direct"); else System.out.println("buffer is not direct"); } } |
chevron_right
filter_none
Output:
buffer is direct
Examples 2:
// Java program to demonstrate // isDirect() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // defining and allocating ByteBuffer // using allocate() method ByteBuffer byteBuffer = ByteBuffer.allocate(4); // check the byteBuffer // using isDirect() method boolean val = byteBuffer.isDirect(); // checking the condition if (val) System.out.println("buffer is direct"); else System.out.println("buffer is not direct"); } } |
chevron_right
filter_none
Output:
buffer is not direct
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#isDirect–
Recommended Posts:
- Buffer isDirect() methods in Java with Examples
- ByteBuffer put() methods in Java with Examples | Set -1
- ByteBuffer clear() methods in Java with Examples
- ByteBuffer putLong() methods in Java with Examples
- ByteBuffer putInt() methods in Java with Examples
- ByteBuffer position() methods in Java with Examples
- ByteBuffer mark() methods in Java with Examples
- ByteBuffer limit() methods in Java with Examples
- ByteBuffer flip() methods in Java with Examples
- ByteBuffer putFloat() methods in Java with Examples
- ByteBuffer putChar() methods in Java with Examples
- ByteBuffer putDouble() methods in Java with Examples
- ByteBuffer wrap() methods in Java with Examples
- ByteBuffer putShort() methods in Java with Examples
- ByteBuffer rewind() methods in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

