-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetDemo.java
More file actions
37 lines (31 loc) · 782 Bytes
/
HashSetDemo.java
File metadata and controls
37 lines (31 loc) · 782 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
29
30
31
32
33
34
35
36
37
/* Studying HashSet */
import java.util.*;
public class HashSetDemo
{
public static void main(String args[])
{
HashSet <Object> hs = new HashSet();
MyOwnClass ob1 = new MyOwnClass();
MyOwnClass ob2 = new MyOwnClass("Switzerland",25);
String name1 = "Santhosh";
String name2 = "Unnikrishnan";
Integer num1 = new Integer(10);
Integer num2 = new Integer(20);
Integer num3 = new Integer(30);
hs.add(ob1);
hs.add(ob2);
hs.add(name1);
hs.add(name2);
hs.add(num1);
hs.add(num2);
hs.add(num3);
System.out.println("Contents of HashSet ");
System.out.println(hs);
Iterator <Object> itr = hs.iterator();
System.out.println("Contents of HashSet using Iterator" );
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}