set 遍历
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
轉載于:https://www.cnblogs.com/xiaolin-peter/p/7001341.html
總結
- 上一篇: 云+网+端 技术架构
- 下一篇: javascript:void(0)与#