Java: convert List to a String

前端 未结 22 2590
日久生厌
日久生厌 2020-11-22 01:03

JavaScript has Array.join()

js>[\"Bill\",\"Bob\",\"Steve\"].join(\" and \")
Bill and Bob and Steve

Does Java have anything

22条回答
  •  情深已故
    2020-11-22 01:41

    With java 1.8 stream can be used ,

    import java.util.Arrays;
    import java.util.List;
    import java.util.stream.Collectors;
    List list = Arrays.asList("Bill","Bob","Steve").
    String str = list.stream().collect(Collectors.joining(" and "));
    

提交回复
热议问题