The toShort() method is utilized to convert the specified int number into a short type value.
Method Definition: (Number).toShort
Return Type: It returns the converted short datatype value.
Example 1:
Scala
// Scala program of Int toShort() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying toShort method
val result = ( 1 ).toShort
// Displays output
println(result)
}
} |
Output:
1
Example 2:
Scala
// Scala program of Int toShort() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying toShort method
val result = ( 187449572 ).toShort
// Displays output
println(result)
}
} |
Output:
16612