public class StringEmpty {
public static void main(String[] args) {
String str1 =
null;
String str2 = ""
;
String str3 = "i have a dream!"
;
String[] array =
new String[]{str1, str2, str3};
for (String str : array) {
System.out.println(str ==
null);
System.out.println("str.isEmpty() ?" + (""
).equals(str));
System.out.println("valid str Not Empty ? " +
validString(str));
System.out.println("======================================="
);
}
}
public static boolean validString(String string) {
if (
null == string || (""
).equals(string)) {
return false;
} else
return true;
}
}
测试结果如下:
转载于:https://www.cnblogs.com/binfoo/p/5589001.html