How to avoid comma atlast while displaying error



Sample Code:

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

Integer i;
Integer len;
mail.add(test@test.com);
mail.add(test1@test.com);
mail.add(test2@test.com);
mail.add(test3@test.com);

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

}

No comments:

Post a Comment