Suggestion: Add the method isEmpty in the classes StringBuilder and StringBuffer

Hildeberto Mendonça me at
Mon Feb 11 11:54:35 UTC 2013


we have a scenario where a project with approximately 500K lines of code is
going through a large refactoring. One of the changes was to replace string
concatenations in loops by StringBuilder. Within the logic we found the
following condition:

for(...) {
   if(str.isEmpty()) {
      // do something

After using StringBuilder,we had to change it to:

for(...) {
   if(str.length() == 0) {
      // do something

... which is a less readable code than the previous code. Having shown
that, we would like to know if there was a previous discution on the
inclusion or not of a method isEmpty in the StringBuilder. if yes, why it
is not there, if no, can we actually have it on Java8 or in a near future?

We can actually find other similar String-like methods within
StringBuilder, such as charAt, replace and others.

We would like to know if it is worthwhile to be discussed and taken forward.

Best regards,

Hildeberto Mendonça, Ph.D
Twitter: <>

More information about the core-libs-dev mailing list