How to join list of strings with a separator using Apex in Salesforce?

How to join list of strings with a separator using Apex in Salesforce?

String.join() method can be used to join list of strings with a separator using Apex in Salesforce.

Sample Code:

List < String > strList = new List < String > { 'Test 1', 'Test 2', 'Test 3' };  
String str = String.join( strList, ', ' );  
System.debug( 'Joined with coma is ' + str );  

Output:

Leave a Reply