Play Games

Search This Blog

Friday, September 24, 2021

How to convert array(list) to a string with values separated with semicolon in apex - Salesforce Globe For You

How to convert array(list) to a string with values separated with semicolon in apex - Salesforce Globe For You

Problem: I have one list lstAlphabet as List<String> lstAlphabet = new List<String>{'a','b','c','d'}

I want to convert that list to string as a;b;c;d

Sample Code:

String strFinalString = '';

List<String> lstAlphabet = new List<String>{'a','b','c','d'};

for(String aphabet : lstAlphabet) {

    if(!string.ISEMPTY(strFinalString)) {

        strFinalString = strFinalString+';'+aphabet;

    } else {

        strFinalString = aphabet;

    }

}

system.debug('Final String:::'+strFinalString);

Output:



No comments:

Post a Comment