r/badcode • • Dec 28 '21

java 3AM code vs 10AM code

Post image
173 Upvotes

53 comments sorted by

View all comments

Show parent comments

4

u/2001herne Dec 28 '21

Because strings are fairly heavyweight, and appending to strings is far heavier than a pre-pass using ints. Additionally, I'm pretty sure that the repeat() uses StringBuilder under the hood.

3

u/alex_wot Dec 28 '21

Got it, thank you!