Join strings with different last delimiter

前端 未结 7 1135
感情败类
感情败类 2021-01-04 12:04

Using stream.collect(Collectors.joining(\", \")) I can easily join all the strings of my stream delimited by a comma. A possible result would be \"a, b, c

相关标签:
7条回答
  • 2021-01-04 12:57

    Try joining the last 2 strings first with stream.collect(Collectors.joining(" and "))

    Then join all remaining strings and this new string with the code you used in your question: stream.collect(Collectors.joining(", ")).

    0 讨论(0)
提交回复
热议问题