Concatenating Strings with += inside a loop copies every character written so far on every iteration—turning 50,000 appends into over a billion character copies. StringBuilder solves that in linear O(n) time using a single resizable mutable buffer.
More lessons in Complete Core Java