Java.lang.Double.shortValue() Method


Advertisements


Description

The java.lang.Double.shortValue() method returns the value of this Double as a short (by casting to a short).

Declaration

Following is the declaration for java.lang.Double.shortValue() method

public short shortValue()

Parameters

NA

Return Value

This method returns the double value represented by this object converted to type short.

Exception

NA

Example

The following example shows the usage of java.lang.Double.shortValue() method.

package com.tutorialspoint;

import java.lang.*;

public class DoubleDemo {

   public static void main(String[] args) {

      /* returns the double value represented by this object
         converted to type short */
      Double obj = new Double("3.5");
      short s = obj.shortValue();
      System.out.println("Value = " + s);
    
      obj = new Double("2");
      s = obj.shortValue();
      System.out.println("Value = " + s);
   }
}  

Let us compile and run the above program, this will produce the following result −

Value = 3
Value = 2

java_lang_double.htm

Advertisements