I have write the code as:
public class Solution { public int[] intersection(int[] nums1, int[] nums2) { HashSet<Integer> has1 = new HashSet(Arrays.asList(nums1)); for (int i: has1) System.out.println(i); return nums1; } } num1: [1,2,4,2,3] num2: [4,5,6,3] On the for loop it says java.lang.ClassCastException: [I cannot be cast to java.lang.Integer
intandIntegerare not the same type. Fix the type in theforand it should work.new HashSet<>(IntStream.of(nums1).boxed().collect(Collectors.toList())), you're currently getting aHashSet<int[]>and using a raw-type so you're also ignoring a warning.