Java – How to convert a bool or string value to Boolean in Java ?


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

Problem Statement

You need to convert a boolean value of string value to Boolean type in your java program.

Solution

Use the Boolean class’s constructor and pass the corresponsing parameter to change it.


Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book

Below is the sample code snippet demonstrating how to do it.

public class Main {

    public static void main(String[] args) {

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

        Boolean b1 = new Boolean("false");
        Boolean b2 = new Boolean(false);
        System.out.println(b1);
        System.out.println(b2);

    }
}


The output of the above program is

Abundantcode.com Java Tutorials

false

false

%d bloggers like this: