Java.lang Package Classes

Java - String valueOf() Method



The Java string valueOf() method returns the string representation of the float argument.

Syntax

public static String valueOf(float f)

Parameters

f specify a float.

Return Value

Returns a string representation of the float argument.

Exception

NA.

Example:

In the example below, valueOf() method returns the string representation of the given argument.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    float x1 = 125.25f;
    System.out.println(String.valueOf(x1));  

    float x2 = -125.25f;
    System.out.println(String.valueOf(x2));

  }
}

The output of the above code will be:

125.25
-125.25

❮ Java.lang - String