Java.lang Package Classes

Java - String valueOf() Method



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

Syntax

public static String valueOf(boolean b)

Parameters

b specify a boolean.

Return Value

Returns "true" if the argument is true; otherwise, "false" is returned.

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) {
    boolean x1 = true;
    System.out.println(String.valueOf(x1)); 

    boolean x2 = false;
    System.out.println(String.valueOf(x2));
  }
}

The output of the above code will be:

true
false

❮ Java.lang - String