java.lang.String valueOf(double d)

Description :

This java tutorial shows how to use the valueOf(double d) method of String class of java.lang package. This method returns a string representation of double data type. This will yield the same result as Double.toString(double).

Method Syntax :

public static String valueOf(double d)

Parameter Input :

DataType Parameter Description
double d method parameter which we are interested to get the string equivalent

Method Returns :

The String valueOf() method with argument double returns a new String object which corresponds to the string representation of the method argument.

Compatibility Version :

Since the beginning

Exception :

None

Discussion :

The string valueOf(double d) method is simply to get a String equivalent of float method parameter. This method be statically accessed which means we should call the method like String.valueOf(double d).

Java Code Example :

This example source code demonstrates the use of valueOf(double d) of String class. Below are different examples of getting a value of double. As you would noticed we have used the unboxing functionality to transform a Double object into double primitive datatype and then get the string equivalent using the valueOf method.

package com.javatutorialhq.java.tutorial.string;

/*
 * Java example source code to get the value of primitive double data type
 */

public class StringValueOfFloat {

	public static void main(String[] args) {

		// primitive double declaration
		double val = 1.0123;
		// Object of Double data type
		Double valueDouble = 100.125123;
		System.out.println(String.valueOf(val));
		System.out.println(String.valueOf(valueDouble));
		System.out.println(String.valueOf(123.123123));
	}

}

Sample Output :

Running the valueOf() method example source code of String class will give you the following output

java string indexOf(double) method example

java string indexOf(double) method example

Exception Scenario :

N/A

Suggested Reading List :

References :