java 给list中的每个元素都加上单引号并用逗号隔开
1.用java1.8中的stream:
-
List<String> list = new ArrayList<>();
-
list.add("110");
-
list.add("120");
-
String ids = list.stream().map(s -> "\'" + s + "\'").collect(Collectors.joining(", "));
-
System.out.println(ids);
输出结果:'110','120'