Java Boolean.valueOf() Method Example

The Boolean.valueOf() method returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE.

Java Boolean.valueOf() Method Example

public class BooleanClassExample {
 
 public static void main(String[] args) {
  valueOf();
 }

 private static void valueOf(){
  // creating boolean variable
     boolean b1 = true;
     boolean b2 = false;
      
     // getting Boolean objects from boolean variables
     Boolean b3 = Boolean.valueOf(b1);
     Boolean b4 = Boolean.valueOf(b2);
      
     System.out.println(b3);
     System.out.println(b4);
 }
 
}
Output:
true
false

Reference

Comments