Set<String>set = new HashSet<String>();
set.add("c");
set.add("d");
set.add("a");
set.add("a");
//方法一:
List<String>list = new ArrayList<String>(set);
for(Strings : list) {
System.out.println(s);
}
System.out.println();
//方法二:
List<String>list2 = new ArrayList<String>();
list2.addAll(set);
for(Strings : list2) {
System.out.println(s);
}
List<String>list = new ArrayList<String>();
list.add("c");
list.add("d");
list.add("a");
list.add("a");
//方法一:
Set<String>set = new HashSet<String>(list);
for(Strings : set) {
System.out.println(s);
}
System.out.println();
//方法二:
Set<String>set2 = new HashSet<String>();
set2.addAll(list);
for(Strings : set2) {
System.out.println(s);
}
注:list转成set后: