How to find the common elements in two array?

common elements in two array


								
package com.tech.mindclues;

public class CommonElementsInTwoArray {
	public static void main(String args[]) {

		// Declare two array type of integer
		int ar1[] = { 2, 4, 5, 5, 6, 7 };
		int ar2[] = { 1, 6, 5, 4, 8, 9, 7 };
		
		System.out.println("Common elements :");
		
		for (int i : ar1) {
			for (int j : ar2) {
				if (i == j) {
					System.out.println(i);
				}
			}

		}
	}

}

							

								
Common elements :
4
5
5
6
7
							

Related Articles

post a comment