This is a Java program that demonstrates how to convert a string to a boolean value.
Note that the Boolean constructor can also take a boolean value as a parameter and return a Boolean object that represents the same value. Additionally, the String class provides a static method valueOf that can be used to convert a string to a boolean value, which returns a primitive boolean rather than a Boolean object.
import java.util.Scanner; public class String_toBoolean { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the String : "); String str = input.next(); // Convert string to boolean using constructor Boolean bool = new Boolean(str); System.out.println("Boolean value is : " +bool); } }
Enter the String : Java Boolean value is : false
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions