Why when concatenating a String in Java inside the for loop the "+" operator is slow?
Anonymous User
58

I've been solving one leetcode problem and I needed to concatenate the String inside the for loop. I've solved it innitially with the simple "+" oparator and I've passed all the test cases but the result was not efficient. After that I went to discussions and found a solution with the StringBuilder. The code was very similar but just inside the for loop the concatenation has been implemented with StringBuilder' append method. I beat 100% solutions with that implementation. Can someone explain me please why the "+" operator is that slow? Thanks!

Comments (1)