-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hset.java
57 lines (42 loc) · 1.08 KB
/
Hset.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
55
56
57
package sets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Hset {
public static void main(String[] args) {
Set<Integer> s1 = new HashSet<Integer>();
s1.add(56);
s1.add(42);
s1.add(90);
s1.add(76);
s1.add(32);
s1.add(90);
s1.add(42);
// 32 56 42 90 76 - 1st
System.out.println("Hashset");
Iterator<Integer> itr = s1.iterator();
while (itr.hasNext()) {
System.out.print(itr.next() + " ");
}
System.out.println();
System.out.println("======================================================================");
ArrayList<Integer> aList = new ArrayList<Integer>();
aList.add(55);
aList.add(31);
aList.add(55);
aList.add(31);
aList.add(67);
aList.add(90);
aList.add(67);
aList.add(90);
Iterator L_itr = aList.iterator();
while(L_itr.hasNext())
{
System.out.print(L_itr.next()+" ");
}
System.out.println();
Set<Integer> hs1 = new HashSet<Integer>(aList);
System.out.println(hs1);
}
}