List、Set互转
// List转Set
Set<String> set = new HashSet<>(list);
System.out.println("set: " + set);
// Set转List
List<String> list_1 = new ArrayList<>(set);
System.out.println("list_1: " + list_1);
Array、Set互转
// array转set
s = new String[]{"A", "B", "C", "D","E"};
set = new HashSet<>(Arrays.asList(s));
System.out.println("set: " + set);
// set转array
dest = set.toArray(new String[0]);
System.out.println("dest: " + Arrays.toString(dest));
当前位置: 首页 > 技术研究 > Java > java set序列与其他集合转换

java set序列与其他集合转换

发布于:2021-2-9 Java 0条评论 222 views
List、Set互转
// List转Set
Set<String> set = new HashSet<>(list);
System.out.println("set: " + set);
// Set转List
List<String> list_1 = new ArrayList<>(set);
System.out.println("list_1: " + list_1);
Array、Set互转
// array转set
s = new String[]{"A", "B", "C", "D","E"};
set = new HashSet<>(Arrays.asList(s));
System.out.println("set: " + set);
// set转array
dest = set.toArray(new String[0]);
System.out.println("dest: " + Arrays.toString(dest));

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据