-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetRemove.java
More file actions
29 lines (28 loc) · 1.05 KB
/
Copy pathHashSetRemove.java
File metadata and controls
29 lines (28 loc) · 1.05 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
import java.util.*;
public class HashSetRemove {
public static void main(String[] args) {
HashSet<String> set=new HashSet<String>();
{
set.add("HARSH");
set.add("ssvdsf");
set.add("egtfvg");
set.add("egtrfs");
set.add("etfg");
set.add("gte");
System.out.println("An inital list of elements"+set);
set.remove("HARSH");
System.out.println("After removing an element"+set);
HashSet<String> set1=new HashSet<String>();
set.add("jjjioioi");
set.add("hgbjerkr");
set.addAll(set1);
System.out.println("Updated list"+set);
set.removeAll(set1);
System.out.println("After removing all elements"+set);
set.removeIf(str->str.contains("jjjioioi"));
System.out.println("After removing all elements"+set);
set.clear();
System.out.println("After clearing all elements"+set);
}
}
}