LongBuffer limit() method in Java with Examples
The limit() method of java.nio.LongBuffer Class is used to modify this LongBuffer’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.
public final LongBuffer limit(int newLimit)
Parameter: The method takes one parameter newLimit of integer type which refers to the limit that is to be set as the new limit of the buffer.
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:
LongBuffer before setting buffer's limit: [20, 30, 0, 0] Position: 2 Limit: 4 LongBuffer after setting buffer's limit: [20, 30, 0, 0] Position: 1 Limit: 1
LongBuffer before setting buffer's limit: [20, 30, 40, 0, 0] Position: 3 Limit: 5 LongBuffer before setting buffer's limit: [20, 30, 40, 0, 0] Position: 3 Limit: 4
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.