set 遍历
1.測(cè)試類
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循環(huán)遍歷");
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.測(cè)試結(jié)果
方法一:for循環(huán)遍歷
abc
edf
? ? ?hij
? 方法二:迭代遍歷
? ? ?abc
? ? ?edf
? ? ?hij
轉(zhuǎn)載于:https://www.cnblogs.com/xiaolin-peter/p/7001341.html
總結(jié)
- 上一篇: 云+网+端 技术架构
- 下一篇: 16_内容回顾