- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Convert Java String Object to Boolean Object
A string object can be created in Java using the string literal.
String myStr = “Amit”;
Another way to create a string object is using the new keyword.
String myStr = new String("Hello!");
We have used the first method to create a string object.
String str = "true";
Now, use the valueOf() method to convert String Object to Boolean Object. We have used this method on Boolean object.
Boolean bool = Boolean.valueOf(str);
Let us now see the complete example to show how to convert String Object to Boolean Object.
Example
public class Demo { public static void main(String[] args) { String str = "true"; // conversion Boolean bool = Boolean.valueOf(str); System.out.println(bool); } }
Output
True
Advertisements