This is not the most efficient way, but it may be the easiest way to work in Java:
public static void main(final String[] args) { final int[] a = { 1, 2, 3, 4, 5 }; final int[] b = { 3, 1, 2 }; // we have to do this just in case if there might some values that are missing in a and b // example: a = { 1, 2, 3, 4, 5 }; b={ 2, 3, 1, 0, 5 }; missing value=4 and 0 findMissingValue(b, a); findMissingValue(a, b); } private static void findMissingValue(final int[] x, final int[] y) { // loop through the bigger array for (final int n : x) { // for each value in the a array call another loop method to see if it in there if (!findValueSmallerArray(n, y)) { System.out.println("missing value: " + n); // break; } } } private static boolean findValueSmallerArray(final int n, final int[] y) { for (final int i : y) { if (n == i) { return true; } } return false; }
source share