How to check null on StringBuilder?

前端 未结 6 2227
自闭症患者
自闭症患者 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:42

    The below code may help you,

    StringBuffer sb = new StringBuffer();
    String str = sb.toString();
    if(!"".equals(str)) {
        System.out.println("String : " + str);
    } else {
        System.out.println("Empty Builder");
    }
    

提交回复
热议问题