import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class Test {
public static void main(String[] args) {
Set<String> set = new HashSet<String>(); //生成Set
set.add("apple"); //set添加数据
List<String> list = new ArrayList<String>();//生成List
Iterator<String> it = set.iterator(); //遍历Set
while(it.hasNext()){
list.add(it.next().toString()); //Set转化List
}
Iterator<String> it2 = list.iterator(); //遍历List
while(it2.hasNext()){
System.out.println(it2.next()); //输出List
}
}
} |
|