- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to create a boolean variable from string
Use the parseBoolean() method to create a boolean variable from a string. Here for boolean variable, firstly take a boolean and pass the string to it using Boolean.parseBoolean().
boolean val1 = Boolean.parseBoolean("TRUE");
The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
Do the same for FALSE as well.
boolean val2 = Boolean.parseBoolean("FALSE");
Let us now see the complete example to form a boolean variable from string.
Example
public class Demo { public static void main(String[] args) { boolean val1 = Boolean.parseBoolean("TRUE"); System.out.println(val1); boolean val2 = Boolean.parseBoolean("FALSE"); System.out.println(val2); } }
Output
true false
- Related Articles
- Swift program to convert boolean variable into string
- Swift program to convert string type variable into boolean
- Create a Boolean object from Boolean value in Java
- Java Program to convert String to Boolean
- Java Program to convert Boolean to String
- Program to evaluate Boolean expression from a string in Python?
- Java Program to Create String from Contents of a File
- Java Program to create Stream from a String/Byte Array
- Java Program to create a BigDecimal from a string type value
- Java Program to create Character Array from String Objects
- Java Program to convert boolean value to Boolean
- Python program to create a dictionary from a string
- Parse a string to a Boolean object in Java
- How to create a string from a Java Array?
- How to create a string from a Java ArrayList?

Advertisements