LongBuffer mismatch(LongBuffer) in Java

mismatch(LongBuffer): This method is available in java.nio.LongBuffer class of Java.

Syntax:

int java.nio.LongBuffer.mismatch(LongBuffer that)

This method takes one argument of type LongBuffer as its parameter. This method finds and returns the relative index of the first mismatch between this buffer and a given buffer.

Note: If the two buffers share a common prefix then the returned index is the length of the common prefix.

Parameters: One parameter is required for this method.

that: The byte buffer to be tested for a mismatch with this buffer.

Returns: The relative index of the first mismatch between this and the given buffer, otherwise -1 if no mismatch.

Exceptions: NA

Approach

Java

import java.nio.LongBuffer;

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

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

        long array2[] = { 1, 2, 4, 5 };
        LongBuffer that = LongBuffer.wrap(array2);
        System.out.println(lb.mismatch(that));
    }
}

Output:

2


No comments:

Post a Comment