-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList_Arraylist.java
54 lines (33 loc) · 1.16 KB
/
List_Arraylist.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
package com.mywork;
import java.util.ArrayList;
import java.util.List;
public class List_Arraylist { //list to array list
public static void main(String[] args) {
List<Integer> a = new ArrayList<Integer>();
a.add(10);
a.add(20);
a.add(50);
a.add(20);
a.add(50);
a.add(70);//method --add
List<Integer> b = new ArrayList<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
//System.out.println(b);
//b.removeAll(a);
//System.out.println(b);//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 = b.toArray(); //convert list to array
for (Object object : array) {
System.out.println(object);
}
String c = b.toString();//convert list to string
System.out.println(c);
}
}