VOOZH about

URL: https://www.geeksforgeeks.org/java/java-integer-compareunsigned-method/

⇱ Java Integer compareUnsigned() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Integer compareUnsigned() method

Last Updated : 4 Apr, 2023

The compareUnsigned() method of the Integer class of java.lang package compares two integer values (x, y) given as a parameter, treating the values as unsigned and returns the value zero if (x==y), if (x < y) then it returns a value less than zero, and if (x > y) then it returns a value greater than zero. 

Syntax:

public static int compareUnsigned(int x, int y)
Parameter :
x : the first int to compare
y : the second int to compare
Return :
This method returns the value zero if (x==y), 
if (x < y) then it returns a value less than zero 
and if (x > y) then it returns a value greater than zero,
treating the values(x, y) as unsigned.

Example 01 :To show working of java.lang.Integer.compareUnsigned() method. 

Output:

-1
0
1
-1

Example 02: To show the working of 'compareUnsigned()' method. 

Output:

x is greater than y
Comment