forked from MLSA-Mehran-UET/Learn-to-code-java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashsett.java
More file actions
Latest commit
57 lines (54 loc) · 1.73 KB
/
Copy pathhashsett.java
File metadata and controls
57 lines (54 loc) · 1.73 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
packagearrayprog;
importjava.util.Scanner;
importjava.util.HashSet;
publicclasshashsett {
publicstaticvoidmain (String[] args) {
Scannersc=newScanner(System.in);
HashSet <String> so = newHashSet <>();
while(true){
System.err.println("Select operation u want to perform \n 1) ADD \n 2) Remove \n 3) CONTAIN \n 4) SiZE \n 5) EMPTY \n 6) CLEAR \n 7) EXIT");
inta=sc.nextInt();
switch(a){
case1:
System.out.println("Enter Length");
intb=sc.nextInt();
System.out.println("Enter "+ b + "Names");
for(inti=0; i<b; i++)
{
System.out.println("Enter Name");
Stringc=sc.next();
so.add(c);
}
break;
case2:
System.out.println("Enter index u want to Remove");
Stringd=sc.next();
so.remove(d);
case3:
{
for (Stringc: so)
System.out.println(" Elements of Set are "+ so.contains(c));
}
break;
case4:
{
System.out.println("The Size of the set is "+ so.size());
}
break;
case5:
{
System.out.println(so.isEmpty());
}
break;
case6:
{
System.out.println("Hash set is"+so);
so.clear();
System.out.println("After Clear Hash set is"+so);
}
break;
case7:
System.exit(7);
}
}
}}