It's an O(n)
algorithm either way (unless you did some multi-threaded solution where you broke the list into multiple sublists, but I don't think that is what you are asking for).
Just use a StringBuilder
as below:
StringBuilder sb = new StringBuilder();
for (Object obj : list) {
sb.append(obj.toString());
sb.append("\t");
}
String finalString = sb.toString();
The StringBuilder
will be a lot faster than string concatenation because you won't be re-instantiating a String
object on each concatenation.