-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo19.java
More file actions
119 lines (89 loc) · 2.62 KB
/
Demo19.java
File metadata and controls
119 lines (89 loc) · 2.62 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// import java.util.Iterator;
// import java.util.Set;
// import java.util.TreeSet;
// class Counter {
// int i;
// public synchronized void increment() {
// i++;
// }
// }
public class Demo19 {
public static void main(String[] args) {
// 71. Race Condition In Java
// Counter c = new Counter();
// Runnable r1 = () -> {
// for (int i = 1; i <= 1000; i++) {
// c.increment();
// }
// };
// Runnable r2 = () -> {
// for (int i = 1; i <= 1000; i++) {
// c.increment();
// }
// };
// Thread t1 = new Thread(r1);
// Thread t2 = new Thread(r2);
// t1.start();
// t2.start();
// try {
// t1.join();
// t2.join();
// } catch (InterruptedException ex) {
// }
// System.out.println(c.i);
// =============================================
// =============================================
// 72. ArrayList In Java
// Collection<Integer> n = new ArrayList<Integer>();
// n.add(9);
// n.add(3);
// n.add(5);
// n.add(1);
// for (int i : n) {
// System.out.println(i);
// }
// System.out.println(n);
// =============================================
// =============================================
// 73. List In Java
// List<Integer> a = new ArrayList<Integer>();
// a.add(5);
// a.add(3);
// a.add(1);
// a.add(9);
// System.out.println(a.get(1));
// System.out.println(a.set(0, 6));
// System.out.println(a.indexOf(9));
// for (int i : a) {
// System.out.println(i);
// }
// System.out.println(a);
// =============================================
// =============================================
// 74. Set In Java
// Set<Integer> s = new HashSet<Integer>();
// s.add(55);
// s.add(37);
// s.add(94);
// s.add(14);
// s.add(92);
// System.out.println(s.contains(3));
// for (int i : s) {
// System.out.println(i);
// }
// Set<Integer> s = new TreeSet<Integer>();
// s.add(55);
// s.add(37);
// s.add(94);
// s.add(14);
// s.add(92);
// Iterator<Integer> i = s.iterator();
// System.out.println(i.next());
// while (i.hasNext()) {
// System.out.println(i.next());
// }
// for (int n : s) {
// System.out.println(n);
// }
}
}