Site icon Automation Dojos

Concatenate Strings Using String.join() for Collections

There is an overloaded version of the String.join method that accepts as parameter an Iterable implementation. Since all Collection classes implement the Iterable interface, this method can be used to concatenate all the elements in a Collection. The following code demonstrates this:

This code creates a List of String values and passes this List to the String.join method with a “/” as the delimiter. So, this code prints the following output:
red/blue/green/white

Exit mobile version