Repository navigation
Expand file tree
/
Copy pathArrayListExample.java
More file actions
70 lines (54 loc) · 1.69 KB
/
Copy pathArrayListExample.java
File metadata and controls
70 lines (54 loc) · 1.69 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
package Arrays;
import java.util.ArrayList;
import java.util.List;
public class ArrayListExample {
public static void main(String[] args) {
ArrayList<Integer> list_1 = new ArrayList<>();
list_1.add(17);
list_1.add(28);
list_1.add(30);
ArrayList<Integer> list_2 = new ArrayList<>();
list_2.add(99);
list_2.add(16);
list_2.add(8);
compareTriplets(list_1,list_2);
//Syntax
ArrayList<Integer> list = new ArrayList<>();
list.add(34);
list.add(345);
list.add(657);
// System.out.println(list);
list.remove(0);
// System.out.println(list);
list.add(35);
// System.out.println(list);
list.add(2,5);
System.out.println(list);
ArrayList<Integer> list1 = solve(list);
System.out.println(list1);
}
public static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
// List<Integer> resultList = new List<Integer>();
List<Integer> list = new ArrayList<Integer>(2);
list.add(0);
list.add(0);
for(int i = 0; i<a.size();i++){
if(a.get(i) > b.get(i)){
int count = list.get(0);
list.set(0, count+1);
}else if (a.get(i) < b.get(i)){
int count = list.get(1);
list.set(1, count+1);
}
}
return list;
}
static ArrayList<Integer> solve(final List<Integer> A) {
ArrayList<Integer> list = new ArrayList<>();
for(int i = A.size()-1; i >= 0; i--){
list.add(A.get(i));
System.out.println(A.get(i));
}
return list;
}
}