代码示例
import java.util.*;
public class CollectionTransform {
public static void main(String[] args) {
// List 转化为Array
ArrayList<String> strings = new ArrayList<>();
strings.add("12345");
strings.add("456");
strings.add("789");
String[] strings1 = strings.toArray(new String[strings.size()]);
//将Array 转化为List
List<String> strings2 = Arrays.asList(strings1);
// 将Array 转化为set
String [] countries = {"India", "Switzerland", "Italy"};
Set<String> set = new HashSet<String>(Arrays.asList(countries));
System.out.println(set);
//map 转化为set
Map<Integer, String> sourceMap = new HashMap<>();
Set<String> targetSet = new HashSet<>(sourceMap.values());
}
}