Can we rely on String.isEmpty for checking null condition on a String in Java?

前端 未结 6 2392
南旧
南旧 2020-12-24 10:44

I am passing an accountid as input from an XML file as shown, which will be parsed later and will be used in our code:

123456         


        
6条回答
  •  情深已故
    2020-12-24 11:20

    You can't use String.isEmpty() if it is null. Best is to have your own method to check null or empty.

    public static boolean isBlankOrNull(String str) {
        return (str == null || "".equals(str.trim()));
    }
    

提交回复
热议问题