Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Convert String to Boolean example

  1. /*
  2.  * Convert String to Boolean example. Program to convert Java
  3.  * String object to Boolean object.
  4.  */
  5.  
  6. public class StringToBoolean {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("true");
  12.  
  13.   //Use Boolean(String) constructor
  14.   Boolean bObj1 = new Boolean(str);
  15.  
  16.   //OR Use static valueOf(String) method of Boolean class
  17.   Boolean bObj2 = Boolean.valueOf(str);
  18.  
  19.   System.out.println("String converted to Boolean: " + bObj1);
  20.  
  21.  }
  22.  
  23. }
No votes yet
Share this

Post new comment

3 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.