r/learnjava • u/ReasonableTwo8 • Jan 12 '21
Java Interview Questions and Answers
Came across this while preparing myself, you can refer to this if you are preparing for Java interview. Hope you find this useful. :)
68
Upvotes
r/learnjava • u/ReasonableTwo8 • Jan 12 '21
Came across this while preparing myself, you can refer to this if you are preparing for Java interview. Hope you find this useful. :)
1
u/Kombatnt Jan 13 '21
I apologize, I wasn't trying to provoke anyone. You're right, I neglected to consider the situation where a String is being built up in a loop. I'm not denying that a StringBuilder would be faster than String concatenation in that situation - I'm simply saying that (at least in my opinion), it doesn't matter. String concatenation is more readable, so that's the approach I would prefer.
In my experience, and in virtually all literature I've read, performance concerns take a distant back seat to readability and maintainability. I merely meant to push back a little against the dogmatic pursuit of squeezing every last nanosecond of performance out of an otherwise simple construct.