1import java.util.HashSet;
2import java.util.Set;
3
4class IterateHashSet{
5 public static void main(String[] args) {
6 Set<String> hset = new HashSet<String>();
7 hset.add("Chaitanya");
8 hset.add("Rahul");
9
10 for (String temp : hset) {
11 System.out.println(temp);
12 }
13 }
14}
1import java.util.HashSet;
2import java.util.Iterator;
3
4class IterateHashSet{
5 public static void main(String[] args) {
6 HashSet<String> hset = new HashSet<String>();
7 hset.add("Chaitanya");
8 hset.add("Rahul");
9
10 Iterator<String> it = hset.iterator();
11 while(it.hasNext()){
12 System.out.println(it.next());
13 }
14 }
15}