1.测试类
import org.junit.Test;
public class Study {
@Test
public void test() {
Set<String> set = new HashSet<String>();
set.add("abc");
set.add("edf");
set.add("hij");
System.out.println("方法一:for循环遍历");
for (String in : set) {
System.out.println(in);
}
System.out.println("方法二:迭代遍历");
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String value = it.next();
System.out.println(value);
}
}
}
2.测试结果
方法一:for循环遍历
abc
edf
hij
方法二:迭代遍历
abc
edf
hij