Java String Concatenation
In Java, you use either the String concatenation + operator or StringBulder class methods such as append. Since Java compilers frequently create intermediate objects when the + operator is used and don't when StringBuilder.append is used, the append method is faster than the + operator.
In general, use the convenience of a + operator when speed is not an issue. For example, when concatenating a small number of items and when code isn't executed very frequently. A decent rule of thumb is to use the + operator for general purpose programming and then optimize the + operator with StringBuilder.append as needed.
Syntax Example: Simple + operator example:
System.out.println("Hello" + " " + "Mike.");
Using StringBuilder example:
StringBuilder myMsg = new StringBuilder();
myMsg.append("Hello ");
myMsg.append("Mike.");
System.out.println(myMsg);