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

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;
    }

}

测试结果如下:

posted @ 2016-06-15 21:45  binfoo  阅读(1447)  评论(0编辑  收藏  举报