IntBuffer limit(int) in Java

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

Syntax:

IntBuffer java.nio.IntBuffer.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.

Exceptions: NA

Approach

Java

import java.nio.IntBuffer;

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

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

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

Output:

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


limit()



No comments:

Post a Comment