-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashset.java
54 lines (44 loc) · 1.05 KB
/
Hashset.java
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
import java.util.HashSet;
import java.util.Iterator;
class Hashset
{
public static void main(String args[])
{
HashSet<Integer> set = new HashSet<Integer>();
//Vlaue is Add for Hashset
System.out.println("Add Elements for set.");
set.add(10);
set.add(20);
set.add(30);
set.add(10); //HashSet is only contain qunick Value
set.add(40);
set.add(50);
set.add(60);
//Display all Values
System.out.println("Display Elements for set.");
System.out.println(set);
//Remove Elements in set
System.out.println("10 is Remove Element for Set.");
set.remove(10);
System.out.println(set);
//Searsh element of Hashset
if(set.contains(60))
{
System.out.println("Hashset containt 60");
}
if(!set.contains(80))
{
System.out.println("Hashset does not containt 80");
}
//size of the Hashset
System.out.println("Count the Size of set");
System.out.println(set.size());
//Iterator
System.out.println("Iterator in Hashset");
Iterator it = set.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}