
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Integer to Boolean in Java with Specified Values
To convert an Integer to a boolean, we have taken the following Integer objects.
Integer one = 1; Integer two = 1; Integer three = 0;
We have taken nested if-else statement to display the true or false values. Here, the value “one” is the same as “two” i.e. 1; therefore, the following else-if works.
else if (one.equals(two)) { System.out.println(true); }
The above display “true” and in this way we converted Integer to boolean.
Let us now see the complete example to learn how to convert an Integer to Boolean.
Example
public class Demo { public static void main(String[] args) { Integer one = 1; Integer two = 1; Integer three = 0; // Integer to Boolean if (one == null) { if (two == null) { System.out.println(true); } else if (three == null) { System.out.println(false); } } else if (one.equals(two)) { System.out.println(true); } else if (one.equals(three)) { System.out.println(false); } } }
Output
True
Advertisements