Java.lang Package Classes

Java Double - longValue() Method

The java.lang.Double.longValue() method returns the value of this Double as a long after a narrowing primitive conversion.


public long longValue()


No parameter is required.

Return Value

Returns the double value represented by this object converted to type long.




In the example below, the java.lang.Double.longValue() method returns a Double object after conversion to type long.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating Double objects
    Double val1 = 25.2;
    Double val2 = -25.2;

    //printing longValue of the Double objects
    System.out.println("longValue of the val1 is: " + val1.longValue()); 
    System.out.println("longValue of the val2 is: " + val2.longValue());   

The output of the above code will be:

longValue of the val1 is: 25
longValue of the val2 is: -25

❮ Java.lang - Double