Skip to Content

Convert Java String Object to Boolean Object

  1. /*
  2.   Convert java String object to Boolean object
  3.   This example shows how to convert java String object to a Java Boolean object.
  4. */
  5. public class JavaStringToBoolean {
  6.  
  7.   public static void main(String[] args) {
  8.     //construct String object
  9.     String str = "false";
  10.    
  11.     //1. Convert using constructor
  12.     Boolean blnObj1 = new Boolean(str);
  13.     System.out.println(blnObj1);
  14.    
  15.     //2. Use valueOf method of Boolean class. This is a static method.
  16.     Boolean blnObj2 = Boolean.valueOf(str);
  17.     System.out.println(blnObj2);
  18.   }  
  19. }
  20.  
  21. /*
  22. Output would be
  23. false
  24. false
  25. */