Normally, when dealing with text,
you should use String. There are good reasons why it is
immutable - for example, this makes it much easier to make concurrent programs and makes optimizations such as string pooling possible.
Use StringBuilder when you need to build up text, for example by repeatedly appending things. Have a look at this example:
This code is very inefficient, because of the repeated String concatenations in the loop. For each iteration, a new String object will be made, for which the content of 'result' until that point will have to be copied. So this is what happens:
i = 1: result = new String object containing "A, B"
i = 2: result = new String object, first "A, B" is copied into it and then ", C" is appended
i = 3: result = new String object, first "A, B, C" is copied into it and then ", D" is appended
i = 4: result = new String object, first "A, B, C, D" is copied into it and then ", E" is appended
i = 5: ...
You see that every time the result until now is copied into a new String object - that's very inefficient. You can avoid this by using StringBuilder:
StringBuilder is mutable, it only needs to append ", " and names[i] in each iteration and it doesn't need to copy the whole result each time - so it's much more efficient.