IntBuffer compareTo(IntBuffer) in Java

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

Syntax:

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

This method takes one argument of type IntBuffer as its parameter. This method compares this buffer to another.

Two int buffers are compared by comparing their sequences of remaining elements lexicographically.

Parameters: One parameter is required for this method.

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.IntBuffer;

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

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

        int array2[] = { 1, 2, 4, 6 };
        IntBuffer that = IntBuffer.wrap(array2);
        System.out.println(lb.compareTo(that));
    }
}

Output:

-1


No comments:

Post a Comment