Home » Java Integer shortValue() method with Examples

Java Integer shortValue() method with Examples

by Online Tutorials Library

Java Integer shortValue() Method

The shortValue() method of Java Integer class returns the value of this Integer as a short type after a primitive conversion. It overrides the shortValue() method of Number Class.

Syntax:

Following is the declaration of shortValue() method:

Parameter:

DataType Parameter Description
NA NA This method does not take any parameter.

Returns:

The shortValue() method returns the numeric value represented by this object after conversion to type short.

Exceptions:

NA

Compatibility Version:

Java 1.0 and above

Example 1

Test it Now

Output:

Value of s = 225  Value of s = -225  

Example 2

Output:

Enter Desired Number: 46546657  short Value is: 16097  

Example 3

Output:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:   Type mismatch: cannot convert from double to Integer  Type mismatch: cannot convert from String to Integer    at myPackage.IntegerShortValueExample2.main(IntegerShortValueExample2.java:6)  

Next Topicsignum() Method

You may also like