Can Anyone tell me how can I do this in java?
I donβt know about the java part, but for your info in kodular you can just use 1 block, instead of the loop to convert the list to csv (Comma-seperated value)
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.
This post was flagged by the community and is temporarily hidden.
yea I do not know java properly.
This post was flagged by the community and is temporarily hidden.
Ok, so again my posts are being flagged without any reason.
Whoever doing so, kindly pm me.
Yes, but what?
i can try but i am not giving full confirmation as i am also a new coder i having only 1 year experience