The shortValue() is an inbuilt method of the Short class in Java and is used to return the Short value of this value.
public short shortValue()
Parameters: The method does not take any parameter.
Return Value: The method returns the numeric value represented by this object after conversion to type short.
Below programs illustrate the Short.shortValue() method:
The short value of the given Short is = 21
The short value of the given Short is = -19
Note: It returns an error message when a decimal value and string is passed as an argument.
prog.java:10: error: incompatible types: possible lossy conversion from double to short short svalue = 9.6; ^ prog.java:18: error: incompatible types: String cannot be converted to short short svalue2 = "61"; ^ 2 errors
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.