Searching...
Saturday, 10 December 2016

How to find out common elements between two arrays

08:00

Java program

package com.vinod.test;


/**
 * Class to find common numbers from two arrays
 *
 *@authorvinodkariyathungalkumaran
 *
 */
public class FindCommonNumbers {

    public static void main(String[] args) {
        int array1[] = { 12, 13, 14, 15, 16, 17 };
        int array2[] = { 12, 18, 29, 15, 7, 17 };

        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j < array2.length; j++) {
                if (array1[i] == array2[j]) {
                    System.out.println(array1[i]);
                }
            }
        }

    }

}

Output

12
15
17


0 comments: