```
public int[] intersection(int[] nums1, int[] nums2) {
Set<Integer> intersect = IntStream.of(nums1).boxed()
.collect(Collectors.toSet());
intersect
.retainAll(IntStream.of(nums2).boxed().collect(Collectors.toSet()));
return intersect.stream().mapToInt(x -> x).toArray();
}
```

This is a illustration how strong Java 8 is. You can write 5 lines to do this while it'll take 15 lines or so in Java 7. With IntStream you can totally get away from all the manual boxing/unboxing.