Arrays.compareUnsigned(short[], short[]) in Java

Arrays.compareUnsigned(short[], short[]): This method is available in java.util.Arrays class of Java.

Syntax:

int java.util.Arrays.compareUnsigned(short[] a, short[] b)

This method takes two arguments of type short array as its parameters. This method compares two short arrays lexicographically, numerically treating elements as unsigned.

Parameters: Two parameters are required for this method.

a: the first array to compare.

b: the second array to compare.

Returns:

1. The value 0 if the first and second arrays are equal and contain the same elements in the same order.

2. A value less than 0 if the first array is lexicographically less than the second array.

3. A value greater than 0 if the first array is lexicographically greater than the second array.

Exceptions: NA

Approach

Java

import java.util.Arrays;

public class ArrayscompareUnsignedshort {

    public static void main(String[] args) {
        // for short type
        short shortArraya[] = { 55, 67, 188, 678, 90 };

        short shortArrayb[] = { 55, 67, 345, 68, 890 };

        System.out.println(Arrays.compareUnsigned(shortArraya,
shortArrayb));
    }
}

Output:

-157


No comments:

Post a Comment