public int[] intersection(int[] nums1, int[] nums2) {

Set<Integer> result = new HashSet<>();

```
List<Integer> numList = Arrays.stream(nums2).boxed().collect(Collectors.toList());
for (int a1 : nums1) {
if (numList.contains(a1)) {
result.add(a1);
}
}
int[] res = new int[result.size()];
int i = 0;
for (Integer aResult : result) {
res[i] = aResult;
i++;
}
return res;
}
```