Java Integer compareUnsigned() method Last Updated : 04 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. java // Java program to demonstrate working // of java.lang.Integer.compareUnsigned() method import java.lang.Integer; class Gfg { // driver code public static void main(String args[]) { int a = 100; int b = 200; // as 100 less than 200, Output will be a value less // than zero System.out.println(Integer.compareUnsigned(a, b)); int x = 28; int y = 28; // as 28 equals 28, Output will be zero System.out.println(Integer.compareUnsigned(x, y)); int w = 15; int z = 8; // as 15 is greater than 8, Output will be a value // greater than zero System.out.println(Integer.compareUnsigned(w, z)); int m = 15; int n = -8; // as 15 is greater than -8, // but -8 will be treated as an unsigned number // which will be greater than 15 // Output will be a value less than zero System.out.println(Integer.compareUnsigned(m, n)); } } Output: -1 0 1 -1 Example 02: To show the working of 'compareUnsigned()' method. Java import java.io.*; //imports the java.io package, class GFG { public static void main(String[] args) { int x = -100; int y = 200; // initialize them to the values -100 // and 200 int result = Integer.compareUnsigned(x, y); if (result < 0) { System.out.println( "x is less than y"); // print statement } else if (result > 0) { System.out.println("x is greater than y"); } else { System.out.println("x is equal to y"); } } } Output: x is greater than y Comment More infoAdvertise with us Next Article Java Integer compareTo() method N Niraj_Pandey Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Integer Practice Tags : Java Similar Reads Java Integer compare() method The compare() method of Integer class of java.lang package compares two integer values (x, y) given as a parameter 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 compar 2 min read Java Integer compareTo() method The compareTo() method of Integer class of java.lang package compares two Integer objects numerically and returns the value 0 if this Integer is equal to the argument Integer; a value less than 0 if this Integer is numerically less than the argument Integer; and a value greater than 0 if this Intege 2 min read Short compare() method in Java The compare() method of Short class is used to compare two primitive short values for numerical equality. As it is a static method therefore it can be used without creating any object of Short. Syntax: public static int compare(short x, short y) Parameters: This method accepts two parameters: x: whi 2 min read Java String compareToIgnoreCase() Method In Java, the String compareToIgnoreCase() method compares two Strings lexicographically means in dictionary order by ignoring the case differences. It evaluates the Unicode values of characters sequentially.Example 1: Here, we will use the compareToIgnoreCase() method to compare strings that are lex 2 min read How compare() method works in Java Prerequisite: Comparator Interface in Java, TreeSet in JavaThe compare() method in Java compares two class specific objects (x, y) given as parameters. It returns the value:Â 0: if (x==y)-1: if (x < y)1: if (x > y)Syntax:Â Â public int compare(Object obj1, Object obj2)where obj1 and obj2 are th 3 min read JavaTuples compareTo() method The compareTo() method in org.javatuples is used to compare the order of a Tuple object with the object passed as the parameter. This method can be used for any tuple class object of javatuples library. It returns the difference in the ASCII value of the 1st different element present in the passed o 3 min read Like