思考一下
那当然还是三个步骤
第一二步
Set<String> set = new HashSet<String>();
set.add("peace");
set.add("and");
set.add("love");
第三步有三种方法
转数组,使用迭代器,增强for
//第一种方式 转成数组对象
Object[] obj = set.toArray();
System.out.println(set);
System.out.println("##########");
//第二种 使用迭代器
Iterator<String> it = set.iterator();
while(it.hasNext()) {
String s = it.next();
System.out.println(s);
}
System.out.println("##########");
//第三种 增强for
for (String s : set) {
System.out.println(s);
}
运行结果