Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Boolean.valueOf() method is used to return a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".

Syntax

public static Boolean valueOf(String s)

Parameters

s Specify a string.

Return Value

Returns the Boolean value represented by the string.

Exception

NA.

Example:

In the below example, the java.lang.Boolean.valueOf() method is used to return a Boolean object holding the boolean value given by the specified String.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating strings holding boolean values
    String s1 = "true";
    String s2 = "false";

    //creating Boolean instance
    Boolean b1 = Boolean.valueOf(s1);
    Boolean b2 = Boolean.valueOf(s2);

    //printing the string 
    System.out.println("The string s1 is: " + s1);
    System.out.println("The string s2 is: " + s2); 

    //printing the Boolean instance 
    System.out.println("The Boolean object b1 is: " + b1);
    System.out.println("The Boolean object b2 is: " + b2);   
  }
}

The output of the above code will be:

The string s1 is: true
The string s2 is: false
The Boolean object b1 is: true
The Boolean object b2 is: false

❮ Java.lang - Boolean