Java - Fastest way to check the size of String

前端 未结 3 2045
无人共我
无人共我 2021-02-08 22:55

I have the following code inside a loop statement.
In the loop, strings are appended to sb(StringBuilder) and checked whether the size of sb has reached 5MB.



        
3条回答
  •  清酒与你
    2021-02-08 23:48

    Consider using a ByteArrayOutputStream and an OutputStreamWriter instead of the StringBuilder. Use ByteArrayOutputStream.size() to test the size.

提交回复
热议问题