18 Aug 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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
1 2 3 4 5 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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
1 2 3 4 5 |
String representation of Boolean in Java... Boolean = true String = true |
No Comments