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 would argue that if you find yourself composing a String in a loop, that constitutes a code smell, and I would seriously consider other/better ways of achieving the desired result. Perhaps a stream operation, a .forEach(), or something else.
Finally, if none of that was appropriate, and a loop really was the best way to do it, I would still use String concatenation unless we're talking about a seriously large number of loop iterations (thousands or more). Readability trumps performance, until performance becomes noticeable.