-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionDemo.java
More file actions
62 lines (41 loc) · 1.25 KB
/
CollectionDemo.java
File metadata and controls
62 lines (41 loc) · 1.25 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
package collectionFrame;
import java.util.ArrayList;
import java.util.List;
public class CollectionDemo {
public static void main(String[] args) {
List<String> om = new ArrayList<>();
om.add("uncle");
om.add("aunt");
om.add("uncle1");
om.add("aunt1");
om.add("uncle2");
om.add("aunt2");
List<String> fm = new ArrayList<>();
fm.add("Dad");
fm.add("Mom");
fm.add("Dad1");
fm.add("Mom1");
fm.add("Dad2");
fm.add("Mom2");
fm.forEach(o->System.out.println(o));
fm.addAll(om);
System.out.println();
fm.forEach(f->System.out.println(f));
System.out.println();
fm.remove(7);
fm.forEach(f->System.out.println(f));
/*
int a = fm.size(); //print fm collection size
System.out.println(a);
for(String n: fm) { //print fm collection data
System.out.println(n);
}
System.out.println();
System.out.println(fm.get(3)); //get position 3 data
System.out.println(fm.contains("Mom")); //checks collection data
fm.add(0,"Grandfather"); //add data in specified array position
System.out.println("--------------------------------");
fm.forEach(f->System.out.println(f)); //another way of printing collection data
*/
}
}