Java.lang.Short Class

Java Short Class

The Short class in the Java.lang , i.e Java.lang.Short package encapsulates a primitive type short value in an object. A single field of type short is included in a Short object.

This class also has methods for converting a short to a String and a String to a short, as well as additional constants and methods that are handy when working with shorts.

Class declaration

The declaration of java.lang.Short class is:

 

public final class Short 
 extends Number 
 implements Comparable<Short>

Fields

S.N Fields & Description
1. static int BYTES
The number of bytes used to represent a short value in two’s complement binary form.
2. static short MAX_VALUE
A constant holding the maximum value a short can have, 215-1.
3. static short MIN_VALUE
A constant holding the minimum value a short can have, -215.
4. static int SIZE
The number of bits used to represent a short value in two’s complement binary form.
5. static Class<Short> TYPE
The Class instance representing the primitive type short.

Java.lang.Short Methods

The java.lang.Short class has a number of methods which are listed below:

 

Member Methods

S.N Methods & Description
1. byte byteValue()
Returns the value of this Short as a byte after a narrowing primitive conversion.
2. static int compare(short x, short y)
Compares two short values numerically.
3. int compareTo(Short anotherShort)
Compares two Short objects numerically.
4. static Short decode(String nm)
Decodes a String into a Short.
5. double doubleValue()
Returns the value of this Short as a double after a widening primitive conversion.
6. boolean equals(Object obj)
Compares this object to the specified object.
7. float floatValue()
Returns the value of this Short as a float after a widening primitive conversion.
8. int hashCode()
Returns a hash code for this Short; equal to the result of invoking intValue().
9. static int hashCode(short value)
Returns a hash code for a short value; compatible with Short.hashCode().
10. int intValue()
Returns the value of this Short as an int after a widening primitive conversion.
11. long longValue()
Returns the value of this Short as a long after a widening primitive conversion.
12. static short parseShort(String s)
Parses the string argument as a signed decimal short.
13. static short parseShort(String s, int radix)
Parses the string argument as a signed short in the radix specified by the second argument. short value.
14. static short reverseBytes(short i)
Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified Returns the value of this Short as a short.
15. short shortValue()
Returns the value of this Short as a short.
16. String toString()
Returns a String object representing this Short’s value.
17. static String toString(short s)
Returns a new String object representing the specified short.
18. static int toUnsignedInt(short x)
Converts the argument to an int by an unsigned conversion.
19. static long toUnsignedLong(short x)
Converts the argument to a long by an unsigned conversion.
20. static Short valueOf(short s)
Returns a Short instance representing the specified short value.
21. static Short valueOf(String s)
Returns a Short object holding the value given by the specified String.
22. static Short valueOf(String s, int radix)
Returns a Short object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Methods inherited

This class inherits the methods of the following class:

  • java.lang.Object
  • java.lang.Number

 

To open the online compiler click here.

 

Also Read: Java – Label Statement

Leave a Reply

Your email address will not be published. Required fields are marked *