Site icon Automation Dojos

Concatenate Strings Using String.concat()

The String class has a method called concat. It accepts as parameter a String value and concatenates it with the current String. The following code demonstrates this:

As before, this code creates string1 and string2. It then invokes the concat() method on string1 and passes string2 as an argument. So, this code also prints the same output as before:
Hello World
Performance-wise, this approach is not much better than using the + operator. Also, unlike the + operator, this approach cannot be used for multiple Strings or other types of values.

Exit mobile version