VOOZH about

URL: https://www.geeksforgeeks.org/java/integer-shortvalue-method-in-java/

⇱ Integer shortValue() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Integer shortValue() Method in Java

Last Updated : 5 Dec, 2018
The Integer.shortValue() is an inbuilt method of java.lang which returns the value of this Integer in the short type . Syntax:
public short shortValue()
Parameters: The method does not take any parameters. Return Value: The method returns the integer value represented by this object after converting it to type short. Below programs illustrate the Integer.shortValue() method: Program 1: For positive integers.
Output:
The Value of sh_value = 763
Program 2: For negative number.
Output:
The Value of sh_value = -43
Program 3: For a decimal value and string. Note: It returns an error message when a decimal value and string is passed as an argument.
Output:
prog.java:10: error: no suitable constructor found for Integer(double)
 Integer sh_object = new Integer(27.51);
 ^
 constructor Integer.Integer(int) is not applicable
 (argument mismatch; possible lossy conversion from double to int)
 constructor Integer.Integer(String) is not applicable
 (argument mismatch; double cannot be converted to String)
1 error
Comment