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

Published on March 9, 2016 by abundantcode

Filed under Java

Last modified March 9, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3186 times

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.

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

C Program to display Inverted half-pyramid using *

Problem Write a program in C to print Inverted half-pyramid using * as shown below.The program shou...

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , ra...

How to append an array to another in JavaScript ?

In JavaScript , you may want to append one array to another array(s) to combine their elements resul...