Java Program for String representation of Boolean

Boolean is a Primitive datatype in Java with two values, TRUE or FALSE. We can interpret Boolean in String or convert Boolean to String using the toString() method.

Let us now see some examples for displaying String representation of Boolean in Java.

Example 1

Following is an example of string representation of Boolean using toString() method:

public class Example {

  public static void main(String[] args) {
    
    System.out.println("String representation of Boolean in Java...");
    
    boolean a = true; 
    
    System.out.println("Boolean = "+a);  

    String str = Boolean.toString(a);  

    System.out.println("String = "+str);  
  }
}

Output

String representation of Boolean in Java...
Boolean = true
String = true

Example 2

Let us now see another example for String representation of Boolean using valueOf() method:

public class Example {

  public static void main(String[] args) {
    
    System.out.println("String representation of Boolean in Java...");
    
    boolean a = false; 
    System.out.println("Boolean = "+a);  

    String str = String.valueOf(a);  
    System.out.println("String = "+str);  
  }
}

Output

String representation of Boolean in Java...
Boolean = true
String = true
Java Program to parse string to a Boolean object
Compare two Boolean Arrays in Java
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment