不假设数组有序和不重复的情况
int[] x = {1, 2, 3, 4, 5, 6, 7};
int[] y = {2, 4, 7};
Map<Integer, Long> count = Arrays.stream(y).boxed()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
int[] z = Arrays.stream(x).boxed()
.map(e -> count.containsKey(e) && count.put(e, count.get(e) – 1) > 0 ? e : 0)
.mapToInt(Integer::intValue).toArray();
System.out.println(“z = ” + Arrays.toString(z));