POSTS

Java - Transform string list into list

Problem:

Transform a list of strings into a single string. One solution is to iterate over the list and append its contents. Remember that StringBuilder’s append is much faster than Strings concatenation.

Solution:

A better solution is relying on Java StringJoiner
<![CDATA[ String.join(“, “, list); ]]>
SyntaxHighlighter.highlight();
, or with Java 8
<![CDATA[ String joinedFirstNames = list.stream() .map(String::toString) .collect(Collectors.joining(“, “)); ]]>
SyntaxHighlighter.highlight();