68
Java Short compareUnsigned() Method
The CompareUnsigned() method of Java Short class is used to compare two Short values numerically and treat every Short value as unsigned. This method is added since jdk 1.9.
Syntax
Parameters
It takes to Short type argument.
X: First Short value to compare
Y: Second Short value to compare
Return value
- Return 0, if unsigned Value of Short x equals to value of Short y.
- Return less than 0, if unsigned value of Short x is less than to the value of Short y.
- Return more than 0, if unsigned value of Short x is greater than to the value of Short y.
Example 1
if unsigned Value of Short x equals to value of Short y.
Output:
when s1= 60 and s2= 60 is Same then result : 0
Example 2
if unsigned value of Short x is less than to the value of Short y.
Output:
when s1= 70 is less than s2= 90 , then result : -20
Example 3
if unsigned value of Short x is greater than to the value of Short y.
Output:
when s1=70 is greater than s2=60 , then result: 10
Next TopicJava Short