分两步
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
本文介绍了一种将Set集合转换为逗号分隔的字符串的方法,首先使用set.toArray()将Set转换为数组,然后利用StringUtils.join()方法将数组元素连接成一个字符串。
1万+

被折叠的 条评论
为什么被折叠?



