Java.lang.Double.valueOf(String s) Method


Advertisements


Description

The java.lang.Double.valueOf(String s) method returns a Double object holding the double value represented by the argument string s.If s is null, then a NullPointerException is thrown.

Declaration

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

public static Double valueOf(String s) throws NumberFormatException

Parameters

s − This is the string to be parsed.

Return Value

This method returns a Double object holding the value represented by the String argument.

Exception

NumberFormatException − if the string does not contain a parsable number.

Example

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

package com.tutorialspoint;

import java.lang.*;

public class DoubleDemo {

   public static void main(String[] args) {

      Double d = new Double("6.5");
      String str = "55";

      /* returns a Double object holding the value represented 
         by str */
      System.out.println("Value = " +  d.valueOf(str));
   }
}  

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

Value = 55.0

java_lang_double.htm

Advertisements