How can I convert List
? E.g. If my List
contains numbers 1 2 and 3 how can it be converted to String = \"1,
Just to add another (of many) options from a popular library (Apache Commons):
import org.apache.commons.lang3.StringUtils;
String joinedList = StringUtils.join(someList, ",");
See documentation: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#join-java.lang.Iterable-java.lang.String-
An elegant option from others' comments (as of Java 8):
String joinedList = someList.stream().map(String::valueOf).collect(Collectors.joining(","));