分两步
1. 将set转为数组set.toArray();
2.将数组转为逗号间隔的字符串 StringUtils.join(arr,",")
代码如下:
Set<String> set = new HashSet<>();
set.add("hello1");
set.add("hello2");
set.add("hello3");
Object[] arr = set.toArray();
System.out.println(StringUtils.join(arr, ","));
输出结果:
hello1,hello2,hello3