خلاصه مطلب
متد ()isEmpty همان طور که از اسمش پیداست ، خالی بودن یک String را چک می کند. این متد اگر یک String خالی بود مقدار true و در غیر این صورت مقدار false را برمیگردا
نوع محتوامقاله آموزشی
موضوعآموزش برنامه نویسی »
زمان مطالعه۱ دقیقه
آخرین ویرایش۲۳ آبان ۱۳۹۶
| public boolean isEmpty() |
| package javalike;public class Test14 { public static void main(String[] args) { String str1 = ""; String str2 = "javalike"; System.out.println(str1.isEmpty()); System.out.println(str2.isEmpty()); } } |
| true false |
| package javalike;public class Test14 { public static void main(String[] args) { String str1 = null; System.out.println(str1.isEmpty()); } } |
| Exception in thread "main" java.lang.NullPointerException at javalike.Test14.main(Test14.java:8) |
| package javalike;public class Test15 { public static void main(String[] args) { String str = null; if (str == null) System.out.println("String is null"); else if (str != null) System.out.println("String is not null"); } } |
| String is null |
| package javalike;public class Test14 { public static void main(String[] args) { String str1 = null; String str2 = "www.javapro.ir"; if (str1 == null || str1.isEmpty()) { System.out.println("String str1 is empty or null"); } else { System.out.println(str1); } if (str2 == null || str2.isEmpty()) { System.out.println("String str2 is empty or null"); } else { System.out.println(str2); } } } |
| String str1 is empty or null www.javapro.ir |
.png)


