1. <i id='qkTND'><tr id='qkTND'><dt id='qkTND'><q id='qkTND'><span id='qkTND'><b id='qkTND'><form id='qkTND'><ins id='qkTND'></ins><ul id='qkTND'></ul><sub id='qkTND'></sub></form><legend id='qkTND'></legend><bdo id='qkTND'><pre id='qkTND'><center id='qkTND'></center></pre></bdo></b><th id='qkTND'></th></span></q></dt></tr></i><div id='qkTND'><tfoot id='qkTND'></tfoot><dl id='qkTND'><fieldset id='qkTND'></fieldset></dl></div>

        <small id='qkTND'></small><noframes id='qkTND'>

      2. <tfoot id='qkTND'></tfoot>

        • <bdo id='qkTND'></bdo><ul id='qkTND'></ul>
        <legend id='qkTND'><style id='qkTND'><dir id='qkTND'><q id='qkTND'></q></dir></style></legend>
      3. 获取两组之间的差异

        时间:2023-10-13

          <small id='VAc4C'></small><noframes id='VAc4C'>

            <legend id='VAc4C'><style id='VAc4C'><dir id='VAc4C'><q id='VAc4C'></q></dir></style></legend>

                <bdo id='VAc4C'></bdo><ul id='VAc4C'></ul>
                <i id='VAc4C'><tr id='VAc4C'><dt id='VAc4C'><q id='VAc4C'><span id='VAc4C'><b id='VAc4C'><form id='VAc4C'><ins id='VAc4C'></ins><ul id='VAc4C'></ul><sub id='VAc4C'></sub></form><legend id='VAc4C'></legend><bdo id='VAc4C'><pre id='VAc4C'><center id='VAc4C'></center></pre></bdo></b><th id='VAc4C'></th></span></q></dt></tr></i><div id='VAc4C'><tfoot id='VAc4C'></tfoot><dl id='VAc4C'><fieldset id='VAc4C'></fieldset></dl></div>
                <tfoot id='VAc4C'></tfoot>

                  <tbody id='VAc4C'></tbody>
                • 本文介绍了获取两组之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以如果我有两套:

                  Set<Integer> test1 = new HashSet<Integer>();
                  test1.add(1);
                  test1.add(2);
                  test1.add(3);
                  
                  Set<Integer> test2 = new HashSet<Integer>();
                  test2.add(1);
                  test2.add(2);
                  test2.add(3);
                  test2.add(4);
                  test2.add(5);
                  

                  有没有办法比较它们,只返回一组 4 和 5?

                  Is there a way to compare them and only have a set of 4 and 5 returned?

                  推荐答案

                  试试这个

                  test2.removeAll(test1);
                  

                  Set#removeAll

                  从此集合中删除指定集合中包含的所有元素(可选操作).如果指定的集合也是一个集合,这个操作有效地修改这个集合,使其值是两个集合的不对称集合差.

                  Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.

                  这篇关于获取两组之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Java 中比较两组的最快方法是什么? 下一篇:在java中获得两组之间对称差异的最佳方法是什么?

                  相关文章

                  <tfoot id='m2MSS'></tfoot>
                    <bdo id='m2MSS'></bdo><ul id='m2MSS'></ul>
                • <legend id='m2MSS'><style id='m2MSS'><dir id='m2MSS'><q id='m2MSS'></q></dir></style></legend>

                      <i id='m2MSS'><tr id='m2MSS'><dt id='m2MSS'><q id='m2MSS'><span id='m2MSS'><b id='m2MSS'><form id='m2MSS'><ins id='m2MSS'></ins><ul id='m2MSS'></ul><sub id='m2MSS'></sub></form><legend id='m2MSS'></legend><bdo id='m2MSS'><pre id='m2MSS'><center id='m2MSS'></center></pre></bdo></b><th id='m2MSS'></th></span></q></dt></tr></i><div id='m2MSS'><tfoot id='m2MSS'></tfoot><dl id='m2MSS'><fieldset id='m2MSS'></fieldset></dl></div>

                      <small id='m2MSS'></small><noframes id='m2MSS'>