isEmpty() gives 20-40% more performance than "".equals().
String equals source code,
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String aString = (String)anObject;
if (coder() == aString.coder()) {
return isLatin1() ? StringLatin1.equals(value, aString.value)
: StringUTF16.equals(value, aString.value);
}
}
return false;
}
Operator instanceOf, class casting, 3 if statements, and all this is just to start the check if the string is actually empty.
Now compare it with String.isEmpty():
public boolean isEmpty() {
return value.length == 0;
}
If we increase the performance in the framework, automatically multiple projects get the benefit.
hacktoberfest
Comment From: snicoll
@sann3 thanks for the follow-up and for making your first contribution to Spring Boot.