Class Short

All Implemented Interfaces:
Comparable<Short>

public final class Short extends Number implements Comparable<Short>
The Short class is the standard wrapper for short values. Since: JDK1.1, CLDC 1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The size of a short in bytes.
    static final short
    The maximum value a Short can have.
    static final short
    The minimum value a Short can have.
    static final int
    The size of a short in bits.
    static final Class<Short>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Short(short value)
    Constructs a Short object initialized to the specified short value.
    Deprecated.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    compare(short s1, short s2)
     
    int
    compareTo(Short another)
    Compares this object to the specified object to determine their relative order.
    static int
    compareUnsigned(short x, short y)
    Compares the two as unsigned values.
    static Short
    Decodes a decimal, hexadecimal or octal short, as Integer.decode.
    double
     
    boolean
    Compares this object to the specified object.
    float
     
    int
    Returns a hashcode for this Short.
    static int
    hashCode(short value)
    The value itself.
    int
     
    long
     
    static short
    Assuming the specified String represents a short, returns that short's value.
    static short
    parseShort(String s, int radix)
    Assuming the specified String represents a short, returns that short's value in the radix specified by the second argument.
    static short
    reverseBytes(short i)
    The bytes in reverse order.
    short
    Returns the value of this Short as a short.
    Returns a String object representing this Short's value.
    static String
    toString(short s)
    The decimal string of s.
    static int
    toUnsignedInt(short x)
    The value as an unsigned int.
    static long
    toUnsignedLong(short x)
    The value as an unsigned long.
    static Short
    valueOf(short i)
    Returns the object instance of i
    static Short
    A Short of parseShort(s).
    static Short
    valueOf(String s, int radix)
    A Short of parseShort(s, radix).

    Methods inherited from class Number

    byteValue

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_VALUE

      public static final short MAX_VALUE
      The maximum value a Short can have. See Also:Constant Field Values
      See Also:
    • MIN_VALUE

      public static final short MIN_VALUE
      The minimum value a Short can have. See Also:Constant Field Values
      See Also:
    • TYPE

      public static final Class<Short> TYPE
    • BYTES

      public static final int BYTES
      The size of a short in bytes.
      See Also:
    • SIZE

      public static final int SIZE
      The size of a short in bits.
      See Also:
  • Constructor Details

  • Method Details

    • equals

      public boolean equals(Object obj)
      Compares this object to the specified object.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hashcode for this Short.
      Overrides:
      hashCode in class Object
    • parseShort

      public static short parseShort(String s) throws NumberFormatException
      Assuming the specified String represents a short, returns that short's value. Throws an exception if the String cannot be parsed as a short. The radix is assumed to be 10.
      Throws:
      NumberFormatException
    • parseShort

      public static short parseShort(String s, int radix) throws NumberFormatException
      Assuming the specified String represents a short, returns that short's value in the radix specified by the second argument. Throws an exception if the String cannot be parsed as a short.
      Throws:
      NumberFormatException
    • shortValue

      public short shortValue()
      Returns the value of this Short as a short.
      Overrides:
      shortValue in class Number
    • toString

      public String toString()
      Returns a String object representing this Short's value.
      Overrides:
      toString in class Object
    • valueOf

      public static Short valueOf(short i)

      Returns the object instance of i

      Parameters
      • i: the primitive
      Returns

      object instance

    • intValue

      public int intValue()
      Specified by:
      intValue in class Number
    • longValue

      public long longValue()
      Specified by:
      longValue in class Number
    • floatValue

      public float floatValue()
      Specified by:
      floatValue in class Number
    • doubleValue

      public double doubleValue()
      Specified by:
      doubleValue in class Number
    • compareTo

      public int compareTo(Short another)
      Description copied from interface: Comparable

      Compares this object to the specified object to determine their relative order.

      Parameters
      • another: the object to compare to this instance.
      Returns
      Specified by:
      compareTo in interface Comparable<Short>
      Returns:

      a negative integer if this instance is less than another; a positive integer if this instance is greater than another; 0 if this instance has the same order as another.

      Throws
      • ClassCastException: @throws ClassCastException if another cannot be converted into something comparable to this instance.
    • compare

      public static int compare(short s1, short s2)
    • toString

      public static String toString(short s)
      The decimal string of s.
    • valueOf

      public static Short valueOf(String s) throws NumberFormatException
      A Short of parseShort(s).
      Throws:
      NumberFormatException
    • valueOf

      public static Short valueOf(String s, int radix) throws NumberFormatException
      A Short of parseShort(s, radix).
      Throws:
      NumberFormatException
    • decode

      public static Short decode(String nm) throws NumberFormatException
      Decodes a decimal, hexadecimal or octal short, as Integer.decode.
      Throws:
      NumberFormatException
    • hashCode

      public static int hashCode(short value)
      The value itself.
    • compareUnsigned

      public static int compareUnsigned(short x, short y)
      Compares the two as unsigned values.
    • toUnsignedInt

      public static int toUnsignedInt(short x)
      The value as an unsigned int.
    • toUnsignedLong

      public static long toUnsignedLong(short x)
      The value as an unsigned long.
    • reverseBytes

      public static short reverseBytes(short i)
      The bytes in reverse order.