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

前端 未结 6 2372
南旧
南旧 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:10

    String s1=""; // empty string assigned to s1 , s1 has length 0, it holds a value of no length string
    
    String s2=null; // absolutely nothing, it holds no value, you are not assigning any value to s2
    

    so null is not the same as empty.

    hope that helps!!!

提交回复
热议问题