Java.lang.Boolean.valueOf() Method



The java.lang.Boolean.valueOf(String s) returns 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".


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

public static Boolean valueOf(String s)


  • s - a string

Return Value

This method returns the Boolean value represented by the string.


  • NA


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

package com.tutorialspoint;

import java.lang.*;

public class BooleanDemo {

   public static void main(String[] args) {

      // create 2 Boolean objects b1, b2
      Boolean b1, b2;

      // create 2 String's and assign values
      String s1 = null;
      String s2 = "false";

       *  static method is called using class name 
       *  assign result of valueOf method on s1, s2 to b1, b2
      b1 = Boolean.valueOf(s1);
      b2 = Boolean.valueOf(s2);

      String str1 = "Boolean instance of string " + s1 + " is "  + b1;
      String str2 = "Boolean instance of string " + s2 + " is "  + b2;

      // print b1, b2 values
      System.out.println( str1 );
      System.out.println( str2 );

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

Boolean instance of string null is false
Boolean instance of string false is false