Java Program to Convert String to Boolean

You are currently viewing Java Program to Convert String to Boolean

Java program to convert string to Boolean

import java.util.Scanner;

public class ConvertStringToBoolean 
{
	public static void main(String[] args) 
	{
		// create object of scanner.
		Scanner KB=new Scanner(System.in);

		// enter path here.
		System.out.print("Enter the string here : ");

		//construct String object
		String str =KB.next();

		// Convert using constructor
		Boolean blnObj1 = new Boolean(str);
		System.out.println("Boolean value is : " +blnObj1);
	}  
}

Output

First run:
Enter the string here : true
Boolean value is : true

Second run:
Enter the string here : false
Boolean value is : false

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply