Q:

Java program to convert string to Boolean

belongs to collection: Java Basic Programs

0

Given input as string and we have to convert it into Boolean value using java program.

Example:

Input string: ‘true’
Output:
Boolean value: true

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to convert string to Boolean in java

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to print \'W\' pattern usin... >>
<< Java program to print Floyd\'s triangle till ...