返回两个数组之间的差异

Posted ...............洋葱的秋秋空间........

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了返回两个数组之间的差异相关的知识,希望对你有一定的参考价值。

public static int[] difference(int[] first, int[] second) {
    Set<Integer> set = Arrays.stream(second).boxed().collect(Collectors.toSet());
    return Arrays.stream(first)
            .filter(v -> !set.contains(v))
            .toArray();
}

 只保留 b 中不包含的值。

以上是关于返回两个数组之间的差异的主要内容,如果未能解决你的问题,请参考以下文章