forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementbetweenArray.java
More file actions
49 lines (33 loc) · 828 Bytes
/
ElementbetweenArray.java
File metadata and controls
49 lines (33 loc) · 828 Bytes
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
import java.io.*;
import java.util.*;
class ElementbetweenArray {
private static void FindCommonElemet(String[] arr1,
String[] arr2)
{
Set<String> set = new HashSet<>();
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; j++) {
if (arr1[i] == arr2[j]) {
// add common elements
set.add(arr1[i]);
break;
}
}
}
for (String i : set) {
System.out.print(i + " ");
}
}
public static void main(String[] args)
{
String[] arr1
= { "Article", "in", "Geeks", "for", "Geeks" };
String[] arr2 = { "Geeks", "for", "Geeks" };
System.out.println("Array 1: "
+ Arrays.toString(arr1));
System.out.println("Array 2: "
+ Arrays.toString(arr2));
System.out.print("Common Elements: ");
FindCommonElemet(arr1, arr2);
}
}