-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetCollections.java
More file actions
28 lines (28 loc) · 873 Bytes
/
HashSetCollections.java
File metadata and controls
28 lines (28 loc) · 873 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
package classFiles;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Iterator;
public class HashSetCollections {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
HashSet<Integer> s=new HashSet<>();
System.out.println("Enter the no of nodes: ");
int n=sc.nextInt();
for(int i=0;i<n;i++){
System.out.print("Enter the "+(1+i)+"th value: ");
int data=sc.nextInt();
s.add(data);
}
if(s.contains(1)) {
System.out.println("The set contains 1");
s.remove(1);
System.out.println("We deleted 1");
}
Iterator i=s.iterator();
System.out.print("The Set is: ");
while(i.hasNext()){
System.out.print(i.next()+" ");
}
}
}