package com.zyl.java;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("0");
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");
list.add("6");
list.add("7");
list.add("8");
list.add("9");
System.out.println(String.join(",",list));
System.out.println(list.stream().collect(Collectors.joining(",")));
}
}
效果:
0,1,2,3,4,5,6,7,8,9
0,1,2,3,4,5,6,7,8,9
关键点:
String.join(",",list)
list.stream().collect(Collectors.joining(","))