Java – How to parse a string to Boolean object in Java ?


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

Problem Statement

You need to parse the string value to the Boolean object in your Java program.

Solution

Use the valueOf static method defined in the Boolean class to parse the string value and convert it to the Boolean object in Java.

public class Main {

    public static void main(String[] args) {

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

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

    }
}
%d bloggers like this: