import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
List<String> cities = Arrays.asList("Milan", "London", "New York", "San Francisco");
String citiesCommaSeparated = String.join(",", cities);
System.out.println(citiesCommaSeparated);
citiesCommaSeparated = cities.stream().collect(Collectors.joining(","));
System.out.println(citiesCommaSeparated);
String SEPARATOR = ",";
StringBuilder csvBuilder = new StringBuilder();
for (String city : cities) {
csvBuilder.append(city);
csvBuilder.append(SEPARATOR);
}
String csv = csvBuilder.toString();
csv = csv.substring(0, csv.length() - SEPARATOR.length());
System.out.println(csv);
}
}