IntBuffer asReadOnlyBuffer() in Java

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

Syntax:

IntBuffer java.nio.IntBuffer.asReadOnlyBuffer()

This method creates a new, read-only int buffer that shares this buffer content.

Parameters: NA

Returns: The new, read-only int buffer.

Exceptions: NA

Approach

Java

import java.nio.IntBuffer;

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

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

        System.out.println(lb.asReadOnlyBuffer());
    }
}

Output:

java.nio.HeapIntBufferR[pos=0 lim=4 cap=4]


No comments:

Post a Comment