-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet_Hashset.java
63 lines (34 loc) · 1.29 KB
/
Set_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
55
56
57
58
59
60
61
62
63
package com.mywork;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Set_Hashset {
public static void main(String[] args) {//Random access -- it doesnot return the dupicate value
Set<Integer> a = new HashSet<Integer>();
a.add(10);
a.add(20);
a.add(50);
a.add(20);
a.add(50);
a.add(70);//method --add
Set<Integer> b = new HashSet<Integer>();
b.add(22);
b.add(61);
b.add(70);
b.add(20);
b.add(33);
b.add(45);
//b.addAll(a); //it add all the value from both index, obj starts from printing statement but it is randomaccess
//System.out.println(b);
//b.removeAll(a);
//System.out.println(b);//remove common valus from printing index what we give from sysout// value deponds on random
//b.retainAll(a);
System.out.println(b);//it retains the same value in the index from sysout what we declare a or b
Object[] array = a.toArray(); //convert list to array using for each loop , w can call any of index
for (Object object : array) {
System.out.println(object);
}
String string = a.toString();//convert list to string
System.out.println(string);
}
}