Need Help From Extension Developers

After looking at some websites in Google, I have a few solutions without using dependencies.

Using StringBuilder

public String convertArrayToCsv(YailList list) {
    Object[] array = list.toArray();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < array.length; i++) {
        sb = sb.append(array[i]);
        if(i != array.length - 1) {
            sb.append(",");
        }
    }
    return sb.toString();
}

toString (not recommended)

public String convertArrayToCsv(YailList list) {
   String strList = list.toArray().toString();
 
   strList = strList.replace("[", "")
                 .replace("]", "")
                 .replace(" ", "");
   return strList;
}

This will replace all spaces including those in the original list value

You can actually use String.join(), however it is only available on java 8, which in extension you can use java 7 only.

2 Likes