ByteBuffer isDirect() methods in Java with Examples Last Updated : 27 Jun, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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"); } } Output: buffer is direct Examples 2: Java // 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"); } } Output: buffer is not direct Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#isDirect-- Comment More infoAdvertise with us Next Article Buffer isReadOnly() methods in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-NIO package Java-ByteBuffer Practice Tags : Java Similar Reads Buffer isDirect() methods in Java with Examples The isDirect() method of java.nio.Buffer Class is used to tell whether or not this 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 2 min read ByteBuffer getInt() method in Java with Examples getInt() The getInt() method of java.nio.ByteBuffer class is used to read the next four bytes at this buffer's current position, composing them into an int value according to the current byte order, and then increments the position by four. Syntax: public abstract int getInt() Return Value: This met 5 min read Buffer isReadOnly() methods in Java with Examples The isReadOnly() method of java.nio.Buffer class is used to tell whether or not this buffer is read-only. Syntax: public abstract boolean isReadOnly() Returns: This method will return true if, and only if, this buffer is read-only. Below are the examples to illustrate the isReadOnly() method: Exampl 2 min read ByteBuffer get() method in Java with Examples get() The get() method of java.nio.ByteBuffer class is used to read the byte at the buffer's current position, and then increments the position. Syntax : public abstract byte get() Return Value: This method returns the byte at the buffer's current position. Throws: This method throws BufferUnderflow 6 min read ByteBuffer mark() methods in Java with Examples The mark() method of java.nio.ByteBuffer Class is used to set this buffer's mark at its position. Syntax: public ByteBuffer mark() Return Value: This method returns this buffer. Below are the examples to illustrate the mark() method: Examples 1: Java // Java program to demonstrate // mark() method i 2 min read ByteBuffer clear() methods in Java with Examples The clear() method of java.nio.ByteBuffer Class is used to clear this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded. Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example: buf.clear(); // Prepa 2 min read Like