English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To convert Integer to boolean value, we use the following Integer object.
Integer one = 1; Integer two = 1; Integer three = 0;
We use nested if-else statement is used to display true or false values. Here, the value ' 1is equal to 2is the same as1; Therefore, the following else-It is feasible if.
else if (one.equals(two)) { System.out.println(true); }
The display is 'true', so we convert Integer to boolean.
Now let's see the complete example to learn how to convert Integer to Boolean.
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 Result
True