ByteBuffer compareTo() in Java

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

Syntax:

int java.nio.ByteBuffer.compareTo(ByteBuffer that)

This method compares this buffer to another.  A byte buffer is not comparable to any other type of object.

Parameters: that the object to be compared.

Returns: A negative integer, zero, or a positive integer as this buffer is less than, equal to, or greater than the given buffer.

Exceptions: NA

Approach

Java

import java.nio.ByteBuffer;

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

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

        ByteBuffer that = ByteBuffer.wrap(array);
        System.out.println(bb.compareTo(that));

    }
}

Output:

0

No comments:

Post a Comment