Java 8 has Collectors.joining() and its overloads. It also has String.join.
Using a Stream and a Collector
Function<String,String> addQuotes = s -> "\"" + s + "\""; String result = listOfStrings.stream() .map(addQuotes) .collect(Collectors.joining(", "));
String result = listOfStrings.stream() .map(s -> "\"" + s + "\"") .collect(Collectors.joining(", "));
String result = listOfString.isEmpty() ? "" : "\"" + String.join("\", \"", listOfStrings) + "\"";
Also published on Medium.
Passionate Developer with 7 years of extensive experience working for Data center related products. Contributed and lead the efforts in Solutioning and engineering in Nimesa Technologies for developing Dataprotection and Copy data management product for Private and Public Clouds
This is my personal weblog, opinions expressed here represent my own and not those of my employer.
All content provided on this blog is for informational purposes only and i will not be liable for any errors, losses, or damages from the display or use of this information.