Java 中如何将 List 集合转换为 Set 集合
可以使用 Set 的构造函数来创建一个新的 Set 对象,将 List 作为参数传递进去即可。例如:
List<String> list = new ArrayList<>();
list.add('a');
list.add('b');
list.add('c');
Set<String> set = new HashSet<>(list);
这样就将 List 转换成了 Set 集合。注意,List 中重复的元素在 Set 中只会出现一次。
原文地址: https://www.cveoy.top/t/topic/oIZK 著作权归作者所有。请勿转载和采集!