- 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
Java Program to convert Boolean to String
To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans.
boolean bool1 = false; boolean bool2 = true;
Now, convert Boolean to String using the toString() method in Java as shown below −
String str1 = new Boolean(bool1).toString(); String str2 = new Boolean(bool2).toString();
Now, when you will display the values “str1” and “str2”, the output would be in String.
Let us now see the complete example to convert Boolean to String.
Example
public class Demo { public static void main(String[] args) { boolean bool1 = false; boolean bool2 = true; String str1 = new Boolean(bool1).toString(); String str2 = new Boolean(bool2).toString(); System.out.println(str1); System.out.println(str2); } }
Output
false true
Advertisements