String[] str = new String[]{"AA", "BB", "CC"};
List list = Arrays.asList(str);
注:Arrays.asList()方法返回的List不能add、remove对象,因为该方法的实现是使用参数引用的数组的大小来new的一个ArrayList
如想进行add、remove操作,应使用如下方式进行转换:
String[] str = new String[]{"AA", "BB", "CC"};
List<String> list = new ArrayList<>();
for(String temp: str){
list.add(temp);
list.add("DD");
list.remove("AA");
数组转Set
String[] str = new String[]{"AA", "BB", "CC"};
Set<String> set = new HashSet<>(Arrays.asList(str));
set.add("DD");
set.remove("AA");
List转数组
Object[] result = list.toArray();
List转Set
Set result = new HashSet(list);
Set转数组
Object[] result = set.toArray();
Set转List
List<String> result = new ArrayList<>(set);