Buffer hasRemaining() methods in Java with Examples Last Updated : 22 Oct, 2022 Comments Improve Suggest changes Like Article Like Report The hasRemaining() method of java.nio.Buffer class is used to tell whether there are any elements between the current position and the limit. Syntax: public final boolean hasRemaining() Returns: This method will return true if, and only if, there is at least one element remaining in this buffer. Below are the examples to illustrate the hasRemaining() method: Example 1: Java // Java program to demonstrate // hasRemaining() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the ByteBuffer int capacity = 10; // creating object of bytebuffer // and allocating size capacity ByteBuffer bb = ByteBuffer.allocate(capacity); // putting the value in bytebuffer bb.put((byte)10); bb.put((byte)20); bb.rewind(); // Typecast bytebuffer to Buffer Buffer buffer = (Buffer)bb; // checking if, there is at least one element // remaining in this buffer. boolean isRemain = buffer.hasRemaining(); // checking if else condition if (isRemain) System.out.println("there is at least one " + "element remaining " + "in this buffer"); else System.out.println("there is no " + "element remaining " + "in this buffer"); } } Output:there is at least one element remaining in this buffer Example 2: Java // Java program to demonstrate // hasRemaining() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the ByteBuffer int capacity = 0; // creating object of bytebuffer // and allocating size capacity ByteBuffer bb = ByteBuffer.allocate(capacity); // Typecast bytebuffer to Buffer Buffer buffer = (Buffer)bb; // checking buffer is backed by array or not boolean isRemain = buffer.hasRemaining(); // checking if else condition if (isRemain) System.out.println("there is at least one " + "element remaining" + " in this buffer"); else System.out.println("there is no " + "element remaining" + " in this buffer"); } } Output:there is no element remaining in this buffer Comment More infoAdvertise with us Next Article Buffer hasRemaining() methods in Java with Examples rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-NIO package Java-Buffer Practice Tags : Java Similar Reads 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 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 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 DoubleBuffer get() methods in Java with Examples The get() method of java.nio.DoubleBuffer Class is used to reads the double at the given bufferâs current position, and then increments the position. Syntax: public abstract double get() Return Value: This method returns the double value at the bufferâs current position. Exception: This method throw 3 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 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 Buffer limit() methods in Java with Examples The limit() method of java.nio.Buffer Class is used to set this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded. Syntax: public Buffer limit(int newLimit) Return Value: This method 2 min read Buffer array() methods in Java with Examples The array() method of java.nio.Buffer class is used to return the array that backs the taken buffer. This method is intended to allow array-backed buffers to be passed to native code more efficiently. Concrete subclasses provide more strongly-typed return values for this method. Modifications to thi 3 min read Like