LongBuffer limit() method in Java with Examples Last Updated : 26 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: 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 LongBuffer // using allocate() method LongBuffer longBuffer = LongBuffer.allocate(4); // put long value in longBuffer // using put() method longBuffer.put(20); longBuffer.put(30); // print the long buffer System.out.println( "LongBuffer before " + "setting buffer's limit: " + Arrays.toString( longBuffer.array()) + "\nPosition: " + longBuffer.position() + "\nLimit: " + longBuffer.limit()); // Limit the longBuffer // using limit() method longBuffer.limit(1); // print the long buffer System.out.println( "\nLongBuffer after " + "setting buffer's limit: " + Arrays.toString( longBuffer.array()) + "\nPosition: " + longBuffer.position() + "\nLimit: " + longBuffer.limit()); } } Output: 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 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 LongBuffer // using allocate() method LongBuffer longBuffer = LongBuffer.allocate(5); // put double value in LongBuffer // using put() method longBuffer.put(20); longBuffer.put(30); longBuffer.put(40); // mark will be going to // discarded by limit() longBuffer.mark(); // print the long buffer System.out.println( "LongBuffer before " + "setting buffer's limit: " + Arrays.toString( longBuffer.array()) + "\nPosition: " + longBuffer.position() + "\nLimit: " + longBuffer.limit()); // Limit the longBuffer // using limit() method longBuffer.limit(4); // print the long buffer System.out.println( "\nLongBuffer before " + "setting buffer's limit: " + Arrays.toString( longBuffer.array()) + "\nPosition: " + longBuffer.position() + "\nLimit: " + longBuffer.limit()); } } Output: 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 Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/LongBuffer.html#rewind-- Comment More infoAdvertise with us Next Article LongBuffer limit() method in Java with Examples rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-NIO package Java-LongBuffer Practice Tags : Java Similar Reads LongBuffer flip() method in Java with Examples The flip() method of java.nio.LongBuffer Class is used to flip this buffer. By flipping this buffer, it meant that the buffer will be trimmed to the current position the then the position will be changed to zero if any mark is there on the buffer, then that mark will be automatically discarded Synta 2 min read LongBuffer rewind() method in Java with Examples The rewind() method of java.nio.LongBuffer Class is used to rewind this buffer. By rewinding this Buffer, the following actions are taken: Current position is set to zero the mark is discarded, if any, but the mark value is unchanged. Syntax: public LongBuffer rewind() Parameter: This method do not 2 min read LongAccumulator longValue() method in Java with Examples The java.LongAccumulator.longValue() is an inbuilt method in java that is equivalent to the get() method that is this method just returns the current value. Syntax: public long longValue() Parameters: This method does not accepts any parameter. Return Value: The method returns the current value. Bel 1 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 LongBuffer equals() method in Java The equals() method of java.nio.LongBuffer Class is used to check whether or not the given buffer is equal to another object. Two Long buffers are equal if, and only if, They have the same element type, They have the same number of remaining elements, and The two sequences of remaining elements, con 4 min read Number.longValue() method in java with examples The Number.longValue() is an inbuilt method in Java of java.lang package. This method is used to convert any numeric value into a long type. This may involve rounding or truncation.What is longValue()?The longValue() method returns the value of a number after converting it to the long data type. Som 2 min read ShortBuffer limit() method in Java with Examples The limit() method of java.nio.ShortBuffer Class is used to modify this ShortBuffer'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 l 3 min read StringBuffer trimToSize() method in Java with Examples The trimToSize() method of StringBuffer class is the inbuilt method used to trims the capacity used for the character sequence of StringBuffer object. If the buffer used by StringBuffer object is larger than necessary to hold its current sequence of characters, then this method is called to resize t 2 min read 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 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 Like