English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
لتحويل Integer إلى قيمة بوليانية، نستخدم الجسم التالي من Integer.
Integer one = 1; Integer two = 1; Integer three = 0;
نستخدم جملة if-else مدمجة لعرض القيم الحقيقية أو الزائفة. هنا، القيمة "1" متطابقة مع "2"، أي 1؛ لذا، else-if التالي يمكن تنفيذه.
else if (one.equals(two)) { System.out.println(true); }
العرض هو "صحيح"، لذا سنقوم بتحويل Integer إلى boolean.
الآن دعونا نرى المثال الكامل لمعرفة كيفية تحويل Integer إلى Boolean.
public class Demo { public static void main(String[] args) { Integer one = 1; Integer two = 1; Integer three = 0; // من عدد صحيح إلى بولياني 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); } } }
نتيجة الخروج
صحيح