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");
String[] str = new String[]{"AA", "BB", "CC"}; Set<String> set = new HashSet<>(Arrays.asList(str)); set.add("DD"); set.remove("AA");
Object[] result = list.toArray();
Set result = new HashSet(list);
Object[] result = set.toArray();
List<String> result = new ArrayList<>(set);