How to check null on StringBuilder?

前端 未结 6 2153
自闭症患者
自闭症患者 2021-02-18 18:39

I want to check for null or empty specifically in my code. Does empty and null are same for StringBuilder in Java?

For example:

StringBuilde         


        
6条回答
  •  有刺的猬
    2021-02-18 19:29

    No. empty means, that there are no characters in the StringBuilder. null means that there is no StringBuilder object at all.

    A variable is only null if it has a reference type (for example String, StringBuilder, Set, as a thumbrule: all capitalized types) and it is not initialised yet or has been set explicitly to null.

提交回复
热议问题