-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashing.java
More file actions
56 lines (39 loc) · 1.02 KB
/
Hashing.java
File metadata and controls
56 lines (39 loc) · 1.02 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
import java.util.HashSet;
import java.util.Iterator;
public class Hashing {
public static void main(String args[]) {
HashSet<Integer> set = new HashSet<>();
//Add
set.add(1);
set.add(2);
set.add(3);
set.add(1);
//Size
System.out.println("size of set is : " + set.size());
//Search
if(set.contains(1)) {
System.out.println("present");
}
if(!set.contains(6)) {
System.out.println("absent");
}
//Delete
set.remove(1);
if(!set.contains(1)) {
System.out.println("absent");
}
//Print all elements
System.out.println(set);
//Iteration - HashSet does not have an order
set.add(0);
Iterator it = set.iterator();
while (it.hasNext()) {
System.out.print(it.next() + ", ");
}
System.out.println();
//isEmpty
if(!set.isEmpty()) {
System.out.println("set is not empty");
}
}
}