Compare two short values

int compareTo(Short anotherShort)
Compares two Short objects numerically.
boolean equals(Object obj)
Compares this object to the specified object.

compareTo(Short anotherShort) compares two Short objects numerically. It returns

Value ReturnedMeaning
0if this Short is equal to the argument Short;
< 0if this Short is numerically less than the argument Short; and
> 0if this Short is numerically greater than the argument Short.

public class Main {
  public static void main(String[] args) {
    Short shortValue1 = new Short("10");
    Short shortValue2 = new Short("11");
    
    System.out.println(shortValue1.compareTo(shortValue2));
  }
}

The output:


-1

public class Main {
  public static void main(String[] args) {
    Short shortValue1 = new Short("10");
    Short shortValue2 = new Short("11");
    
    System.out.println(shortValue1.equals(shortValue2));
  }
}

The output:


false
Home 
  Java Book 
    Essential Classes  

Short:
  1. Short class
  2. Find out the min value, max value and size of Short types
  3. Create Short object with its constructor
  4. Convert Short to byte, double, float, int, long and short
  5. Decode a string to short value
  6. Convert string to a short value
  7. Reverse the bytes in a short
  8. Convert short value to string
  9. Compare two short values