关于字符串是否为空的测试小程序

it2022-05-07  29

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


最新回复(0)