ByteBuffer clear() in Java

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

Syntax:

ByteBuffer java.nio.ByteBuffer.clear()

This method clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

Parameters: NA

Returns: This buffer.

Exceptions: NA

Approach

Java

import java.nio.ByteBuffer;

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

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

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

    }
}

Output:

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

No comments:

Post a Comment