Intersection array from two arrays, Java.
Hi, please could you look at this code, I would like to fill up an empty array of Int appending to it only the common elements from the two first arrays. I am only using java.util.Arrays library, don't want to use any lists or hashset or whatever...just plain for loops and methods for arrays of Int. Could you help me to complete the code? public class Main3 { public static void main(String[] args) { int[] arr1 = {4, 23, 17, 2}; int[] arr2 = {23, 5, 17, 1}; int count=0; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr2.length; j++) { if (list[i] == list1[j]) { count++; int[] common = new int[count]; for (int k = 0; k < common.length; k++) { common[k] = list[i]; } } } } } of course the result is not that I was expecting...:( please help, thanks!