ByteBuffer capacity() in Java

capacity(): This method is available in java.nio.ByteBuffer class of Java.

Syntax:

int java.nio.Buffer.capacity()

This method returns this buffer's capacity.

Parameters: NA

Returns: The capacity of this buffer.

Exceptions: NA

Approach

Java

import java.nio.ByteBuffer;

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

        byte array[] = { 1234 };
        ByteBuffer bb = ByteBuffer.wrap(array);

        System.out.println(bb.capacity());

    }
}

Output:

4

No comments:

Post a Comment