Java – How to get the String representation of the Boolean value in Java ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem statement

You need to convert the Boolean value to string and display the string representation of the same.

Solution

Use the toString static method defined in the Boolean class for the conversion.

public class Main {

    public static void main(String[] args) {

        System.out.println("Abundantcode.com Java Tutorials");

        Boolean b1 = new Boolean("false");
        String str = Boolean.toString(b1);
        System.out.println(str);

    }
}

The output of the above program is

Abundantcode.com Java Tutorials

false

%d bloggers like this: