Buffer isDirect() methods in Java with Examples Last Updated : 16 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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); // Typecast byteBuffer to buffer Buffer buffer = (Buffer)byteBuffer; // check the Buffer // using isDirect() method boolean val = buffer.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); // Typecast byteBuffer to buffer Buffer buffer = (Buffer)byteBuffer; // check the byteBuffer // using isDirect() method boolean val = buffer.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/Buffer.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-Buffer Practice Tags : Java Similar Reads 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 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 Buffer flip() methods in Java with Examples The flip() method of java.nio.ByteBuffer Class is used to flip this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded. After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of 3 min read Buffer mark() methods in Java with Examples The mark() method of java.nio.Buffer Class is used to set this buffer's mark at its position.Syntax: public Buffer 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 import java. 2 min read Buffer 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 3 min read Buffer reset() methods in Java with Examples The reset() method of java.nio.Buffer Class is used to reset this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.Syntax: public Buffer reset() Return Value: This method returns this buffer.Below are the examples to illustrate t 2 min read Like