Java: StringBuffer & Concatenation

后端 未结 6 2029
梦如初夏
梦如初夏 2021-01-05 01:59

I\'m using StringBuffer in Java to concat strings together, like so:

StringBuffer str = new StringBuffer();

str.append(\"string value\");

6条回答
  •  伪装坚强ぢ
    2021-01-05 02:28

    Can you not create a new class which wraps around StringBuffer and add an appendWithTrailingSpace() method?

    CustomStringBuffer str = new CustomStringBuffer();
    str.appendWithTrailingSpace("string value");
    

    (Although you may want to call your method something a little shorter.)

提交回复
热议问题