Javatpoint Logo
Javatpoint Logo

Java Integer compareUnsigned() Method

The compareUnsigned() is a method of Java Integer class which compares two integer objects numerically treating the values as unsigned. It returns the result of the value 0 if both arguments are equal; a value less than 0, if the first argument is less than the second argument; a value greater than 0 will be returned, if the first argument is less than the second argument. This method is specified by Comparable<Integer> Interface.

Note: This method cannot be compared to two different types of argument so, both the argument and the number should be the same type.


Following is the declaration of compareUnsigned() method:


DataType Parameter Description Required/Optional
int x It is the first int value to be compared Required
int y It is the second int value to be compared Required


The compareUnsigned(int x, int y) method will returns the following values:

  • 0 = The value 0 if x=y,
  • -1 = The value less than 0 if x
  • 1 = The value greater than 0 if x>y



Compatibility Version:

Java 1.8 and above

Example 1

Test it Now


Output: 0
Output: -1
Output: 1
Output: -1

Example 2

Test it Now


x is greater than y

Example 3

Test it Now


Enter the first value: -45
Enter the second value: 65
First Value is greater than the second value.

Example 4

Test it Now


Campare the user inputs (unsigned integer): 
The Results are: 

Next Topicdecode() Method

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA