-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemoveDuplicatesFromAnotherArray.java
More file actions
50 lines (43 loc) · 1.07 KB
/
Copy pathRemoveDuplicatesFromAnotherArray.java
File metadata and controls
50 lines (43 loc) · 1.07 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
package learnArrays;
public class RemoveDuplicatesFromAnotherArray {
/**
* Print which in not available in arr2
*
* @author Koushik
*/
public static void main(String[] args) {
char[] arr1 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 's', 't'};
char[] arr2 = {'a', 'b', 'b', 'd', 'f', 'g', 's', 'z', 'x'};
char[] removeDuplicate = removeDuplicate(arr1, arr2);
for (char c : removeDuplicate) {
if (c != 0) {
System.out.print(c);
}
}
}
static char[] removeDuplicate(char[] arr1, char[] arr2) {
char[] tem = new char[arr1.length];
for (int i = 0; i < arr2.length; i++) {
int temp = 0;
for (int j = 0; j < arr1.length; j++) {
if (arr2[i] == arr1[j])
temp++;
}
if (temp == 0)
tem[i] = arr2[i];
// System.out.println(arr2[i]);
}
for (int i = 0; i < arr1.length; i++) {
int temp = 0;
for (int j = 0; j < arr2.length; j++) {
if (arr1[i] == arr2[j])
temp++;
}
if (temp == 0) {
tem[i] = arr1[i];
// System.out.println(arr1[i]);
}
}
return tem;
}
}