Javatpoint Logo
Javatpoint Logo

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA