HashSet
//添加元素
hash.add("abc");
hash.add("java");
hash.add("haah");
//通过增强for循环遍历HashSet
for(String s: hash) {
System.out.println(s);
}
//通过迭代器遍历HashSet
Iterator
while(it.hasNext()) {
System.out.println(it.next());
}
SetstringMap = new HashSet (3);
stringMap.add("string1");
stringMap.add("string2");
stringMap.add("string3");
for (String content : stringMap) {
System.out.println(content);
}
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Test {
public static void main(String[] args) {
Set set = new HashSet();
set.add("123");
set.add("456");
set.add("678");
for (Iterator it = set.iterator(); it.hasNext();) {
System.out.println(it.next());
}
}
}