Whenever you concatenate a string, on each concatenation, you create a new copy of the string and both strings are copied over, one character at a time. This results in a time complexity of O(n2) (McDowell).
If you want to improve performance, use
StringBuilder
One of its constructors has the following syntax:
public StringBuilder(int size); //Contains no character. Initial capacity of 'size'.
StringBuilder (mutable sequence of characters. Remember strings are immmutable) helps resolve this problem by simply creating a resizable array of all the strings. copying them back to a string only when necessary (McDowell).
StringBuilder str = new StringBuilder(0);
str.append(someStr);
str.append(3);
str.append("]");
Reference:
McDowell, Gayle Laakmann. Cracking The Coding Interview, 6th Edition. Print.
"Stringbuilder (Java Platform SE 8 )". Docs.oracle.com. N.p., 2016. Web. 4 June 2016.
StringBuilder
for String concatenation – Quadruplicate