-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet_Linkedhashset0.java
55 lines (33 loc) · 1.14 KB
/
Set_Linkedhashset0.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
package com.mywork;
import java.util.LinkedHashSet;
import java.util.Set;
public class Set_Linkedhashset0 {
public static void main(String[] args) {
Set<Integer> a = new LinkedHashSet<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 LinkedHashSet<>();
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
//System.out.println(b);
//a.removeAll(b);
//System.out.println(a);//remove common valus from printing index what we give from sysout
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);
}
}