DoubleBuffer limit() methods in Java with Examples Last Updated : 29 Jul, 2019 Comments Improve Suggest changes Like Article Like Report The limit() method of java.nio.DoubleBuffer Class is used to modify this DoubleBuffer's limit. This method takes the limit to be set as the parameter and sets that as the new limit of this Buffer. If the mark of this Buffer is already defined and is larger than the new specified limit, then this new limit is not set and discarded. Syntax: public final DoubleBuffer limit(int newLimit) Return Value: This method returns this buffer after setting the specified new limit as the new limit of this Buffer. Below are the examples to illustrate the limit() method: Examples 1: Java // Java program to demonstrate // limit() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // defining and allocating DoubleBuffer // using allocate() method DoubleBuffer doubleBuffer = DoubleBuffer.allocate(4); // put double value in doubleBuffer // using put() method doubleBuffer.put(20.5); doubleBuffer.put(30.5); // print the double buffer System.out.println("DoubleBuffer before " + "setting buffer's limit: " + Arrays.toString( doubleBuffer.array()) + "\nPosition: " + doubleBuffer.position() + "\nLimit: " + doubleBuffer.limit()); // Limit the doubleBuffer // using limit() method doubleBuffer.limit(1); // print the double buffer System.out.println("\nDoubleBuffer after " + "setting buffer's limit: " + Arrays.toString( doubleBuffer.array()) + "\nPosition: " + doubleBuffer.position() + "\nLimit: " + doubleBuffer.limit()); } } Output: DoubleBuffer before setting buffer's limit: [20.5, 30.5, 0.0, 0.0] Position: 2 Limit: 4 DoubleBuffer after setting buffer's limit: [20.5, 30.5, 0.0, 0.0] Position: 1 Limit: 1 Examples 2: Java // Java program to demonstrate // limit() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // defining and allocating DoubleBuffer // using allocate() method DoubleBuffer doubleBuffer = DoubleBuffer.allocate(5); // put double value in DoubleBuffer // using put() method doubleBuffer.put(20.5); doubleBuffer.put(30.5); doubleBuffer.put(40.5); // mark will be going to // discarded by limit() doubleBuffer.mark(); // print the double buffer System.out.println("DoubleBuffer before " + "setting buffer's limit: " + Arrays.toString( doubleBuffer.array()) + "\nPosition: " + doubleBuffer.position() + "\nLimit: " + doubleBuffer.limit()); // Limit the doubleBuffer // using limit() method doubleBuffer.limit(4); // print the double buffer System.out.println("\nDoubleBuffer before " + "setting buffer's limit: " + Arrays.toString( doubleBuffer.array()) + "\nPosition: " + doubleBuffer.position() + "\nLimit: " + doubleBuffer.limit()); } } Output: DoubleBuffer before setting buffer's limit: [20.5, 30.5, 40.5, 0.0, 0.0] Position: 3 Limit: 5 DoubleBuffer before setting buffer's limit: [20.5, 30.5, 40.5, 0.0, 0.0] Position: 3 Limit: 4 Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/DoubleBuffer.html#limit-int- Comment More infoAdvertise with us Next Article DoubleBuffer limit() methods in Java with Examples rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-NIO package Java-DoubleBuffer Practice Tags : Java Similar Reads ByteBuffer limit() methods in Java with Examples The limit() method of java.nio.ByteBuffer 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 ByteBuffer limit(int newLimit) Return Value: Thi 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 DoubleBuffer mark() methods in Java with Examples The mark() method of java.nio.DoubleBuffer Class is used to mark the current position of this DoubleBuffer as the mark of this buffer. Syntax: public DoubleBuffer mark() Return Value: This method returns this DoubleBuffer after setting the buffer's mark at the current position. Below are the example 2 min read CharBuffer limit() methods in Java with Examples The limit() method of java.nio.CharBuffer 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 CharBuffer limit(int newLimit) Return Value: Thi 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 Like