
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Integer compareUnsigned Method
The compareUnsigned() method compares two integer objects numerically considering the values as unsigned.
The return value if 0 if both values are equal; -1 if the val1is less than val2. The return value is 1, if the val1 is more than val2.
At first, set two Integer objects −
int val1 = 50; int val2 = -10;
Now, compare them considering the values as unsigned −
System.out.println(Integer.compareUnsigned(val1, val2));
Following is an example to implement the compareUnsigned() method in Java −
Example
public class Main { public static void main(String[] args) { int val1 = 50; int val2 = -10; int val3 = 200; int val4 = 400; System.out.println(Integer.compareUnsigned(val1, val2)); System.out.println(Integer.compareUnsigned(val2, val3)); System.out.println(Integer.compareUnsigned(val1, val3)); System.out.println(Integer.compareUnsigned(val3, val4)); System.out.println(Integer.compareUnsigned(val3, val3)); } }
Output
-1 1 -1 -1 0
Advertisements