Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StringBuffer append("")

I'm currentlly refactoring an application using a lot of this:

StringBuffer buff1 = new StringBuffer("");

buff1.append("some value A");
buff1.append("");
buff1.append("some value B");

The coder that made those code lines didn't seems to be an idiot, is there any reasons I can't see to use the append("") to a StringBuffer?

like image 492
lemotdit Avatar asked Jan 17 '26 06:01

lemotdit


1 Answers

Nope.

And given that they're hardcoded strings, it'd be identical to write

buff1 = new StringBuffer("some value Asome value B");

BTW, it's a bit more efficient to use a StringBuilder rather than a StringBuffer (and the API is identical).

like image 85
Steve B. Avatar answered Jan 19 '26 18:01

Steve B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!