-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartCombining.java
53 lines (40 loc) · 1.21 KB
/
SmartCombining.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
import java.util.ArrayList;
import java.util.Collections;
public class SmartCombining {
public static void smartCombine(ArrayList<Integer> first, ArrayList<Integer> second){
for(Integer item: first){
if(second.contains(item)){
;
} else {
second.add(item);
}
}
for(Integer thisItem: second){
if(first.contains(thisItem)){
;
} else {
first.add(thisItem);
}
}
}
/*
public static boolean isInside(ArrayList<Integer> first, ArrayList<Integer> second){
for (Integer item: first){
if(second.contains(item)){
return true;
}
}
return false;
}
*/
public static void main(String[] args) {
ArrayList<Integer> list1 = new ArrayList<Integer>();
ArrayList<Integer> list2 = new ArrayList<Integer>();
Collections.addAll(list1, 10, 11);
Collections.addAll(list2, 5);
// remove comment when method ready
smartCombine(list1, list2);
System.out.println(list1);
System.out.println(list2);
}
}