1. 程式人生 > >HashSet的兩種遍歷方式 迭代器 增強for

HashSet的兩種遍歷方式 迭代器 增強for

//通過迭代器遍歷HashSet
Iterator<String> it = hash.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}

System.out.println("==================");

//通過加強for迴圈遍歷HashSet
for(String s: hash) {
System.out.println(s);
}