Home » Java Short compare() method with Examples

Java Short compare() method with Examples

by Online Tutorials Library

Java Short compare() Method

The compare() method of Java Short class compares two Short object numerically. Short is wrapper class.

Syntax

Parameters

X: first short value

Y: second short value

Return value

  • Return 0, if first short value is equal to second short value (x=y).
  • Return less than 0, if first short value less than to second short value (x
  • Return more than 0, if first short value greater than to second short value (x>y).
  • ).

Example 1

when “short x = short y”

Test it Now

Output:

Two short values compared result: 0   

Example 2

Test it Now

Output:

Two short values compared result: -10   

Example 3

Test it Now

Output:

Two short values compared result: 10  

Next TopicJava Short

You may also like