-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetExample.java
More file actions
29 lines (22 loc) · 624 Bytes
/
HashSetExample.java
File metadata and controls
29 lines (22 loc) · 624 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package collection;
import java.util.HashSet;
import java.util.Iterator;
public class HashSetExample {
public static void main(String[] args) {
HashSet<String> countryset = new HashSet<String>();
countryset.add("Nepal");
countryset.add("China");
countryset.add("Nepal");
countryset.add("Japan");
countryset.add("USA");
Iterator<String> itr = countryset.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
countryset.remove("Japan");
System.out.println("********");
for (String country : countryset) {
System.out.println(country);
}
}
}