-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListDemo.java
More file actions
77 lines (54 loc) · 1.79 KB
/
ListDemo.java
File metadata and controls
77 lines (54 loc) · 1.79 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package Collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class ListDemo {
public static void main(String[] args) {
//list creation
List<Integer> list = new ArrayList<Integer>();
list.add(10);
list.add(20);
list.add(30);
list.add(40);
list.add(50);
list.add(60);
int size = list.size();
System.out.println("Size"+ size);
System.out.println("List : " + list);
//Iterate list using for loop
// for(Integer data : list){
// System.out.println(data);
// }
//Using forEach loop
// list.forEach(data -> {
// System.out.println(data) ;
// });
// Using Iterator
// Iterator<Integer> iterator = list.iterator();
// while(iterator.hasNext()){
// System.out.println(iterator.next());
// }
//ListItterator
// ListIterator<Integer> listIterator = list.listIterator();
// while(listIterator.hasNext()){
// System.out.println(listIterator.next());
// System.out.println(listIterator.nextIndex());
// }
System.out.println(list.get(0));
list.remove(5);
System.out.println("Updated List :" + list);
list.set(4, 80);
System.out.println("New List: " + list);
List<Integer> list2 = new ArrayList<>();
list2.add(1000);
list2.add(2000);
list2.add(3000);
System.out.println("List 2" + list2);
list.addAll(list2);
System.out.println("Added List :" +list);
System.out.println("List 1 :" + list);
System.out.println("List 2 :" + list2);
System.out.println(list2.containsAll(list));
}
}