ByteBuffer asIntBuffer() in Java

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

Syntax:

IntBuffer java.nio.ByteBuffer.asIntBuffer()

This method creates a view of this byte buffer as an int buffer. The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, its mark will be undefined, and its byte order will be that of the byte buffer at the moment the view is created.

Note: The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.

Parameters: NA

Returns: A new int buffer.

Exceptions: NA

Approach

Java

import java.nio.ByteBuffer;

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

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

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

    }
}

Output:

java.nio.ByteBufferAsIntBufferB[pos=0 lim=1 cap=1]


No comments:

Post a Comment