public static void main(String[] args) {
List<Integer> ids = Arrays.asList(1, 2, 3);
String idStr = Joiner.on(",").join(ids);
System.out.println("idStr :" + idStr);
// List<Integer> 不可用流的方式
List<String> strIds = Arrays.asList("1", "2", "3");
String idStrs = Joiner.on(",").join(strIds);
System.out.println("idStr :" + idStrs);
// 或
String streamIdStrs = strIds.stream().collect(Collectors.joining(","));
System.out.println("streamIdStrs :" + streamIdStrs);
}
集合拆分字符串,逗号拼接
最新推荐文章于 2023-08-21 16:33:08 发布