Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How does clearing a String Builder affects memory and capacity?

acca71e8-a100-497b-bca3-c6331413eefdNov 2 2015 — edited Nov 2 2015

Hi, i want to clear my string builder to reuse it, i know multiple options:

if we have for example:

StringBuilder token = new StringBuilder("abcdefghijkl");

we can do:

1- token = new StringBuilder("");

2- token.setLength(0);

3- token.delete(0, token.length());

the question is what is the effect of each of 1,2 and 3 on the Capacity of the String Builder and on the Memory?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2015
Added on Nov 2 2015
2 comments
1,822 views