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

Peter Levart peter.levart at gmail.com
Mon Feb 11 12:20:05 UTC 2013


This could be a default method in CharSequence....

Regards, Peter

On 02/11/2013 12:54 PM, Hildeberto Mendonça wrote:
> Hello,
>
> 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,
>




More information about the core-libs-dev mailing list