-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_hash_set.java
More file actions
41 lines (34 loc) · 1.18 KB
/
02_hash_set.java
File metadata and controls
41 lines (34 loc) · 1.18 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
class MyCollections {
public static void main(String args[]) {
example_hashset_string();
}
public static void example_hashset_string() {
// Create using
// HashSet <Data Type> variable = new HashSet <Data Type>();
HashSet<String> workingDaysSet = new HashSet <String>();
workingDaysSet.add("Monday");
workingDaysSet.add("Tuesday");
workingDaysSet.add("Wednesday");
workingDaysSet.add("Thursday");
workingDaysSet.add("Friday");
workingDaysSet.add("Saturday");
// Iterate over the array list
Iterator itor = workingDaysSet.iterator();
System.out.println("\nWorkday Set Size : " + workingDaysSet.size() );
while( itor.hasNext() ) {
System.out.println( itor.next() );
}
// Check item is in hashset or not
if(workingDaysSet.contains("Saturday")==true) {
System.out.println("Saturday is in workingDaysSet" );
} else {
System.out.println("Saturday is not in workingDaysSet" );
}
// Check item is in hashset or not
if(workingDaysSet.contains("Saturday")==true) {
System.out.println("Removing Saturday from workingDaysSet" );
workingDaysSet.remove("Saturday");
}
}
}