LongBuffer limit(int) in Java

limit(int): This method is available in java.nio.LongBuffer class of Java.

Syntax:

LongBuffer java.nio.LongBuffer.limit(int newLimit)

This method takes one argument of type int as its parameter. This method sets this buffer's limit.

Note: 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.

Parameters: One parameter is required for this method.

newLimit: The new limit value; must be non-negative and no larger than this buffer's capacity.

Returns: This buffer.

Approach

Java

import java.nio.LongBuffer;

public class LongBufferlimit2 {
    public static void main(String[] args) {

        long array[] = { 1, 2, 3, 4 };
        LongBuffer lb = LongBuffer.wrap(array);

        int newLimit = 3;
        System.out.println(lb.limit(newLimit));
    }
}

Output:

java.nio.HeapLongBuffer[pos=0 lim=3 cap=4]


limit()


No comments:

Post a Comment