使用该工具类import org.apache.commons.collections.CollectionUtils; 在Apache Jakarta Commons Collections中
String[] strArray = { "aaa", "bbb", "ccc", "bbb" };
List<String> strList = new ArrayList<String>();
Set<String> strSet = new HashSet<String>();
CollectionUtils.addAll(strList, strArray);
CollectionUtils.addAll(strSet, strArray);
for (int i = 0; i < strList.size(); i++) {
System.out.println(strList.get(i));
}
System.out.println("==========");
for (String string : strSet) {
System.out.println(string);
}
输出的结果为
aaa
bbb
ccc
bbb
==========
aaa
ccc
bbb
★ List和Set转换
List list = new ArrayList(new Hashset());
List list = Arrays.asList(array)
list list = new LinkedList(Arrays.asList(array));
Set set = new HashSet(Arrays.asList(array));