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
No, null
and empty
are different for StringBuilder
.
StringBuilder nullBuilder = null;
if(nullBuilder == null) {
System.out.println("Builder is null");
}
&
StringBuilder emptyBuilder = new StringBuilder("");
if(emptyBuilder == null || emptyBuilder.toString().equals("")) {
System.out.println("Builder is empty");
}