How to avoid comma atlast while displaying error

How to avoid comma atlast while displaying error


Sample Code:

List<String> mail = new List<String>();
String error = ”;

Integer i;
Integer len;
mail.add([email protected]);
mail.add([email protected]);
mail.add([email protected]);
mail.add([email protected]);

len = mail.size();
i = 0;
for(String temp:mail)
{
    if(i>len-1)
    {
        error = error + temp + ‘,’;
    }
    else
    {
        error = error + temp;
    }
    i++;

}

Leave a Reply